[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pid of a script?



"ah." wrote:
> 
> I was wondering how to find out the pid of a (bash) script.
> Suppose it's called SCRIPT. Issuing pidof SCRIPT echoes nothing,
> yet ps x shows the pid of it something like /bin/bash ./SCRIPT.
> But then pidof "/bin/bash ./SCRIP" again does nothing. Simply
> saying pidof bash gives the (probably) right result but how many
> bash scripts could there be running at the same time!?

The way to do exactly what you are attempting is something like:

until [ -z `ps ax | grep SCRIPT | awk ' { print $2; } '`]

Or you could use:

echo $$ > /var/run/SCRIPT.pid

in SCRIPT and then:

SCRIPT_PID=`cat /var/run/SCRIPT.pid`

until [ -z `ps ax | grep $SCRIPT_PID` ]

Whichever you prefer.  The second is probably a little more efficient,
but requires modification to two scripts instead of one.

Tom



Reply to: