[PLUG] Extracting the pid from ps -ax

Richard Steffens rsteff at attbi.com
Tue May 21 18:03:32 UTC 2002


The next thing I want to do with my php juke box is to allow for
shutting down a playing mp3 file. I can send a ps -ax command to find
out what the pid is, but I'm having trouble extracting just that number.
I want to use the number so I can create a button that will send kill
(pid).

Can someone suggest a single line command that will extract the pid of
the process that is actually running mpg123 and ignore the processes
related to finding mpg123 in the output of ps?

Here's what I've tried:

ps -ax | grep mpg123

This returns:

 2365 ?        S      0:01 /usr/bin/mpg123
/home/mp3/Classical/BestOfEliotFisk.m
 2369 ?        S      0:00 sh -c ps -ax | grep mpg123
 2371 ?        S      0:00 grep mpg123

Next, I tried:

ps -ax | grep mpg123 | cut -f1

which returns the same thing:

 2365 ?        S      0:01 /usr/bin/mpg123
/home/mp3/Classical/BestOfEliotFisk.m
 2369 ?        S      0:00 sh -c ps -ax | grep mpg123
 2371 ?        S      0:00 grep mpg123

So then I tried:

ps -ax | grep mpg123 | cut -f1 -d' '

which returns nothing, or maybe it returns a space.

Trying:

ps -ax | grep mpg123 | tr -s ' ' ' ' | cut -f1 -d' '

doesn't change anything.

-- 
Regards,

Dick Steffens
"Quando Omni Flunkus Moritati"
http://rsteff.home.attbi.com/




More information about the PLUG mailing list