[PLUG] Extracting the pid from ps -ax
Randal L. Schwartz
merlyn at stonehenge.com
Wed May 22 22:17:52 UTC 2002
>>>>> "D" == D Cooper Stevenson <cooper at linux-enterprise.net> writes:
D> You can also do this:
D> ps -e -o pid -o command | grep -v grep | grep mpg123
D> Experiment with the `-o' switch; you will find it to be a good switch
D> for filtering process lines.
D> The `grep -v grep' part strips out the grep process. Here's an example I
D> ran using Netscape as an argument for grep without the -v switch:
D> 628 netscape
D> 1356 grep netscape
D> When I added ``grep -v grep,' I get this, the correct answer:
D> 628 netscape
I always get freaked at the "grep -v grep" being added ritually.
What's wrong with:
ps c | awk '/netscape/ { print $1 }'
where the "c" flag ensures that the command name is included
*without* its parameters so that you don't get a hit on the grep
in the first place!
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
More information about the PLUG
mailing list