Darrin Chandler <[EMAIL PROTECTED]> wrote:
If you really want to find the parent you can...

$ ps ax -O pgid | grep ntpd
4887  4887 ??  Is      0:00.01 ntpd: [priv] (ntpd)
7164  4887 ??  I       0:00.06 ntpd: ntp engine (ntpd)

The header that gets stripped by grep:
PID  PGID TT  STAT       TIME COMMAND

So you can see that for one process PID==PGID. Bingo.

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

Reply via email to