[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] grepps script...



On Mon, Aug 02, 1999 at 04:13:07PM +0000, Bennett Todd wrote:
> 1999-07-31-11:24:20 Stevie Strickland:
> > This is a script I wrote to grep all the user's processes in the
> > process table *without* returning any of the processes used to do
> > it (unlike a simple `ps ax|grep foo`, which would randomly return
> > the "grep foo" process)...
> 
> There's a standard idiom for doing that. Or rather, as standard as ps(1)
> command-line args and output formats, which isn't very:-).
> 
> Under traditional ps(1) versions, where 'x' is an option you're likely
> to use, add "c" and it'll omit the args, so that the grepper doesn't get
> snagged; for the typical case where all you actually want is the pid this
> compresses to the handy idiom
> 
> 	pid=`ps axc|awk '$NF=="commandname"{print $1}'`

Yeah, okay, I forgot about the "c" option (*blush*)... I guess that
ps axc | grep $1 does the jobs, unless I'm searching for things with
the substring in their arguments (which is very rare, if at all the
case :)

[snip Solaris 2.x and other perl examples]

Wow!  Okay, you've given me a lot to look at, and it's going to take a
while for me to digest it... I hope I can reasonably quickly, since I've
started a Perl/Tk project and getting used to Tk is taking up a lot of
my programming time now... but thanks for the info!  It's much
appreciated :)

Thanks again,
Stevie

-- 
"First they came for the fourth amendment, but I said nothing because I 
wasn't a drug dealer. Then they came for the sixth amendment, but I kept 
quiet because I wasn't guilty. Finally they came for the first amendment,
and by then it was too late to say anything at all." -Nancy Lebowitz

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe