[MLUG] Process ID recycling
Steeve McCauley
steeve at rackable.com
Thu Jul 17 09:59:14 EDT 2008
I always save the pid in /var/run/pname.pid and then do something
like,
pid=$(cat /var/run/pname.pid)
cmd=$(ps -p $pid --no-headers -o %c)
if [ $cmd != pname ]; then
# no longer running
exit 0
fi
# still running
kill $pid
# make sure it's terminated
...
To save the pid in the first place, you can use $! to grok the
last process pid run in the background, or use ps like,
nohup pname > /tmp/out 2>&1 &
pid=$!
or
pid=$(ps -C pname --no-headers -o %p)
David Filion wrote:
> Anyone know what the turnaround time or rule is on a process id being
> reused?
>
> I'm looking for ways to kill a process after a fixed amount of time.
> None of the scripts I've seen so far check that the process ID they
> saved after the fork/exec actually belongs to the process they launched.
>
>
> David
>
>
> _______________________________________________
> mlug mailing list
> mlug at listserv.mlug.ca
> https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
--
Steeve McCauley
Director of Research and Development
Rackable Systems
407 McGill Street, Suite 1002
Montreal, Quebec, H2Y 2G3 (Canada)
Tel: 514-288-3343
http://www.rackable.com
:wq
More information about the mlug
mailing list