Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!usc!bbn!mit-eddie!genrad!decvax!ima!cfisun!lakart!dg
From: dg@lakart.UUCP (David Goodenough)
Newsgroups: comp.unix.questions
Subject: Re: Killing with awk and grep
Message-ID: <657@lakart.UUCP>
Date: 16 Aug 89 14:29:31 GMT
References: <63247@linus.UUCP>
Organization: Lakart Corporation, Newton, MA
Lines: 24

From article <63247@linus.UUCP>, by ccel@chance.uucp (CCEL):
> Funny, we wrote something that did exactly this for one of our
> applications. To be fun, I did it in one line:
> 
> kill -9 `ps -ax | grep 'sleeper' | line | awk '{ print $1 }' `
> 
> Ok ... ps -ax lists the processess, grep finds all occurences of 'sleeper'
> (there should be two ... the actual process, and your grep call). line
> will just return the first line (since sleeper already exists when you
> type this in, it will be first in the ps -ax listing).

Well, I don't know about your ps, but ours sorts by control tty first. So
you don't really know which one will show up. Also, what happens in a case
of PID rollover: the sleeper you're after is PID 29999, and the grep is
(say) 105. A far better replacement for the ..... | line | ..... is this:

..... | grep -v grep | .....

(assuming you have a civilized grep that knows about -v)
-- 
	dg@lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp@xait.xerox.com		  	  +---+