From 34c99f99a51c661ab36ae9a148e2ea2f8e09ecc6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 Jan 2014 17:58:46 -0500 Subject: 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. --- daemon.sh | 4 ++-- 1 file 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 } -- cgit v1.2.3