From owner-freebsd-questions@FreeBSD.ORG Sun May 31 21:04:13 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9424106564A for ; Sun, 31 May 2009 21:04:13 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from mailout.zetnet.co.uk (mailout.zetnet.co.uk [194.247.47.231]) by mx1.freebsd.org (Postfix) with ESMTP id 9D8BF8FC1C for ; Sun, 31 May 2009 21:04:08 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from irwell.zetnet.co.uk ([194.247.47.48] helo=zetnet.co.uk) by mailout.zetnet.co.uk with esmtp (Exim 4.63) (envelope-from ) id 1MAsCJ-0003VH-6n; Sun, 31 May 2009 22:04:03 +0100 Received: from melon.esperance-linux.co.uk (54-144.adsl.zetnet.co.uk [194.247.54.144]) by zetnet.co.uk (8.14.1/8.14.1/Debian-9) with ESMTP id n4VL42ko002973; Sun, 31 May 2009 22:04:02 +0100 Received: by melon.esperance-linux.co.uk (Postfix, from userid 1001) id 2B0CDFCA505; Sun, 31 May 2009 22:03:57 +0100 (BST) Date: Sun, 31 May 2009 22:03:57 +0100 From: Frank Shute To: Steven Schlansker Message-ID: <20090531210357.GA60342@melon.esperance-linux.co.uk> Mail-Followup-To: Steven Schlansker , utisoft@gmail.com, Kelly Jones , freebsd-questions@freebsd.org References: <26face530905311117te38a4faya92733fbfebd9597@mail.gmail.com> <4A22DDAD.8070504@eecs.berkeley.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4A22DDAD.8070504@eecs.berkeley.edu> User-Agent: Mutt/1.4.2.3i X-Face: *}~{PHnDTzvXPe'wl_-f%!@+r5; VLhb':*DsX%wEOPg\fDrXWQJf|2\,92"DdS%63t*BHDyQ|OWo@Gfjcd72eaN!4%NE{0]p)ihQ1MyFNtWL X-Operating-System: FreeBSD 6.4-RELEASE-p2 i386 X-Organisation: 'http://www.shute.org.uk/' X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.1.7 (zetnet.co.uk [194.247.46.1]); Sun, 31 May 2009 22:04:02 +0100 (BST) Cc: Kelly Jones , freebsd-questions@freebsd.org, utisoft@gmail.com Subject: Re: Waiting for a process to die X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Frank Shute List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 May 2009 21:04:14 -0000 On Sun, May 31, 2009 at 12:42:37PM -0700, Steven Schlansker wrote: > > Chris Rees wrote: > >[ `ps ax |grep pid | wc -l ` = 1 ] && (echo "done!" | Mail -s "PROC > >DONE" kelly.terry.jones@gmail.com) > > > > Not always going to work. For example, > > [steven@scs:~]% ps ax | grep init > 1 ? Ss 0:39 init [2] > 13421 pts/1 R+ 0:00 grep init This is why you should use pgrep(1) to find a PID (and kill it) rather than directly grepping a ps output like the previous poster did. > > Also if you use its pid, 1, you get a whole bunch of uninteresting > processes as you're grepping for "1" ;) > > [steven@scs:~]% ps ax | grep 1 | wc -l > 94 > Wojcech nailed the approach the OP should be using. Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html