[PLUG] Extracting the pid from ps -ax (ADDENDUM)

D. Cooper Stevenson cooper at linux-enterprise.net
Tue May 21 19:26:23 UTC 2002


Here's an addendum to my previous post. The following will strip out the
name of the process leaving only the process number. This is capable of
running in a heterogeneous environment:

ps -e -o pid -o command | grep -v grep | grep mpg123 | awk `{ print $1
}'

Pay special attention to the direction of the ticks.


-Cooper



On Tue, 2002-05-21 at 12:16, D. Cooper Stevenson wrote:
> You can also do this:
> 
> ps -e -o pid -o command | grep -v grep | grep mpg123
> 
> Experiment with the `-o' switch; you will find it to be a good switch
> for filtering process lines.
> 
> The `grep -v grep' part strips out the grep process. Here's an example I
> ran using Netscape as an argument for grep without the -v switch:
> 
>  628 netscape
>  1356 grep netscape
> 
> When I added ``grep -v grep,' I get this, the correct answer:
> 
>  628 netscape
> 
> 
> -Cooper
> 
> 
> On Tue, 2002-05-21 at 11:03, Richard Steffens wrote:
> > 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/
> > 
> > _______________________________________________
> > PLUG mailing list
> > PLUG at lists.pdxlinux.org
> > http://lists.pdxlinux.org/mailman/listinfo/plug
> > 
> 
> 
> 
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
> 






More information about the PLUG mailing list