Re: Recording OpenNTPd PID at daemon startup

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <misc@...>
Date: Tuesday, January 29, 2008 - 12:11 pm

Darrin Chandler wrote:

Yes, but there might be a race condition while checking.

What I would like to do is to check if a shell script is already active. And
I don't want to use a lock file:

if [ $(pgrep -of "/bin/sh $0") -ne $MYPID ]; then
echo "I'm already active:" 1>&2
echo $(pgrep -olf "/bin/sh $0") 1>&2
exit 1
fi

If pgrep (with -o support) finds a process that is *older* than MYPID the
script is already active.

afaik that construction is faster than grepping ps, piping and comparing two
values but if there is a better solution I'm pleased to hear about. :)

--
No Swen today, my love has gone away
My mailbox stands for lorn, a symbol of the dawn

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Recording OpenNTPd PID at daemon startup, Helmut Schneider, (Tue Jan 29, 12:11 pm)