diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-14 17:58:46 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-14 17:58:46 -0500 |
commit | 34c99f99a51c661ab36ae9a148e2ea2f8e09ecc6 (patch) | |
tree | 0d7ed9784602bad5daedc95c9431ab35c90c919a | |
parent | 20fa1c5e300c7e0435b368a91cdcda85e99e5fc9 (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.sh | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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 } |