From owner-freebsd-questions@FreeBSD.ORG Mon Nov 27 21:33:23 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 50A9F16A52E for ; Mon, 27 Nov 2006 21:33:23 +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 3E2AC43EC1 for ; Mon, 27 Nov 2006 21:29:07 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.6/8.13.8) id kARLTn9U076298; Mon, 27 Nov 2006 15:29:49 -0600 (CST) (envelope-from dan) Date: Mon, 27 Nov 2006 15:29:48 -0600 From: Dan Nelson To: jhall@vandaliamo.net Message-ID: <20061127212948.GL29363@dan.emsphone.com> References: <2365.65.117.48.155.1164660366.squirrel@admintool.trueband.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2365.65.117.48.155.1164660366.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: Mon, 27 Nov 2006 21:33:23 -0000 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