From owner-freebsd-questions Mon Mar 22 22:37:33 1999 Delivered-To: freebsd-questions@freebsd.org Received: from cc942873-a.ewndsr1.nj.home.com (cc942873-a.ewndsr1.nj.home.com [24.2.89.207]) by hub.freebsd.org (Postfix) with ESMTP id 5086515032 for ; Mon, 22 Mar 1999 22:37:31 -0800 (PST) (envelope-from cjc@cc942873-a.ewndsr1.nj.home.com) Received: (from cjc@localhost) by cc942873-a.ewndsr1.nj.home.com (8.9.3/8.8.8) id BAA10035 for freebsd-questions@FreeBSD.ORG; Tue, 23 Mar 1999 01:37:19 -0500 (EST) (envelope-from cjc) From: "Crist J. Clark" Message-Id: <199903230637.BAA10035@cc942873-a.ewndsr1.nj.home.com> Subject: Process Checking To: freebsd-questions@FreeBSD.ORG (FreeBSD Questions) Date: Tue, 23 Mar 1999 01:37:19 -0500 (EST) Reply-To: cjclark@home.com X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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