From owner-freebsd-questions@FreeBSD.ORG Tue Nov 28 05:05:57 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 71A0F16A4FC for ; Tue, 28 Nov 2006 05:05:57 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id A8EA245AD1 for ; Mon, 27 Nov 2006 23:13:45 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.6/8.13.8) id kARNEZM6019902; Mon, 27 Nov 2006 17:14:35 -0600 (CST) (envelope-from dan) Date: Mon, 27 Nov 2006 17:14:35 -0600 From: Dan Nelson To: jhall@vandaliamo.net Message-ID: <20061127231435.GA69797@dan.emsphone.com> References: <2365.65.117.48.155.1164660366.squirrel@admintool.trueband.net> <20061127212948.GL29363@dan.emsphone.com> <2437.65.117.48.155.1164666185.squirrel@admintool.trueband.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2437.65.117.48.155.1164666185.squirrel@admintool.trueband.net> X-OS: FreeBSD 6.2-PRERELEASE X-message-flag: Outlook Error User-Agent: Mutt/1.5.13 (2006-08-11) Cc: freebsd-questions@freebsd.org Subject: Re: Checking processes without PIDs X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Nov 2006 05:05:57 -0000 In the last episode (Nov 27), jhall@vandaliamo.net said: > > 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. > > > > Yes, that works much better for most of the processes I am testing > against! Two are still giving me problems since their command line > has (perl) listed at the end. Any suggestions on how to better deal > with these two? > > They display as follows > > 422 ?? Ss 8:04.49 /home/postgrey/postgrey --inet=10023 --greylist-text=Greylisted, see http://www.mnea.org/greylisted.html -d (perl) You'll probably need to use the -f option to pgrep to match against the full commandline instead of just the process name: pgrep -f "/home/postgrey/postgrey --inet=10023" I added the first argument to the search string, because if you just use "/home/postgrey/postgrey", then commands like "less /home/postgrey/postgrey" would match. A quick web search indicates that postgrey supports a --pidfile option, so you might want to use that. In fact, the startup script installed by the FreeBSD port seems to include it, so I'm not sure why it's not in your ps output there. -- Dan Nelson dnelson@allantgroup.com