Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Nov 2006 15:29:48 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        jhall@vandaliamo.net
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Checking processes without PIDs
Message-ID:  <20061127212948.GL29363@dan.emsphone.com>
In-Reply-To: <2365.65.117.48.155.1164660366.squirrel@admintool.trueband.net>
References:  <2365.65.117.48.155.1164660366.squirrel@admintool.trueband.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Nov 27), jhall@vandaliamo.net said:
> I have written a script to determine if processes are running.  I am
> using, as an example,
> 
> ps -ax | grep -c postgrey
> 
> Ocassionally, I am receiving a notification a process is not running
> (and it varies which process I receive notifications for).  And, when
> checking, the process actually is running.
> 
> Is there a better way to determine if a process is running than using ps
> and grep?

Reading the program's pidfile and checking to see if that pid still
exists is the best way.  That only works if your program generates a
pidfile, though.  Most of the time they're in /var/run or a
subdirectory.  If it doesn't generate a pidfile, you can try the pgrep
command, which is better than a "ps|grep" combo because it won't ever
accidentally match itself.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061127212948.GL29363>