summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-01-14 17:58:46 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-01-14 17:58:46 -0500
commit34c99f99a51c661ab36ae9a148e2ea2f8e09ecc6 (patch)
tree0d7ed9784602bad5daedc95c9431ab35c90c919a
parent20fa1c5e300c7e0435b368a91cdcda85e99e5fc9 (diff)
daemon: change get_ident()
The new method still uses the start time of the process, but figures and formats it differently. The new way takes the time in "jiffies" since the system booted, using `/proc/$pid/stat`. The old way used `lstart` from `ps`, which calculated the time by adding that to the boot time. This can drift though, as NTP adjusts the system time. I was frequently seeing one second discrepancies, causing duplicate processes to spawn.
-rw-r--r--daemon.sh4
1 files changed, 2 insertions, 2 deletions
diff --git a/daemon.sh b/daemon.sh
index 3fcbc99..4197fc8 100644
--- a/daemon.sh
+++ b/daemon.sh
@@ -2,7 +2,7 @@
get_ident() {
local pid=$1
- ps h -o lstart -p "$pid"
+ cut -d ' ' -f 22 /proc/$pid/stat
}
is_running() {
@@ -44,7 +44,7 @@ main() {
echo "daemon: starting \`$id'"
nohup "$@" > "$OUTFILE" 2> "$ERRFILE" &
pid=$!
- echo "$pid" "`get_ident $pid`" > "$PIDFILE"
+ echo "$pid" "$(get_ident $pid)" > "$PIDFILE"
fi
}