Date: Tue, 23 Mar 1999 01:37:19 -0500 (EST) From: "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com> To: freebsd-questions@FreeBSD.ORG (FreeBSD Questions) Subject: Process Checking Message-ID: <199903230637.BAA10035@cc942873-a.ewndsr1.nj.home.com>
next in thread | raw e-mail | index | archive | help
I've got a question about monitoring a daemon. It's a server for a
game and not the most stable piece of software you have ever seen. I
want to run a cron job periodically to check if the process has not
died, and if it has, restart it.
This is the way I have it now after being slightly surprised by the
behavior of ps(1),
svrpid=`cat $svr/.newstartd.pid`
# check if its is running
if ! ( ps -p $svrpid | grep $svrpid ); then
echo "$0: $svr server not running"
cd $svr
./newstartd &
cd ..
fi
The file $svr/.newstartd.pid holds the last pid of the server. I 'ps'
that process and then 'grep' the return to make sure it is there. If it
is not, I restart it.
Now, I originally just had '! ps -p $svrpid' as the condition in the
if-statement until I realized ps(1) does _not_ return an error
(non-zero) when the pid it's asked to look up does not exist.
My question is:
Is there a more reliable and graceful way to check if a process,
identified by pid, is still alive? The '(ps | grep)' combo is somewhat
of an ugly kludge... but I can't think of when it would fail either.
Thanks.
--
Crist J. Clark cjclark@home.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903230637.BAA10035>
