Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Listing Processes

by Jaspersan (Beadle)
on Jun 21, 2002 at 05:12 UTC ( [id://176227]=perlquestion: print w/replies, xml ) Need Help??

Jaspersan has asked for the wisdom of the Perl Monks concerning the following question:

hey monks,

i need to get the process id's for all perl processes or every process. i was thinking about running a pipe to 'ps', but parsing the output would be a pain. Is there anyway i can do this?

^jasper <jasper@wintermarket.org>

Replies are listed 'Best First'.
Re: Listing Processes
by zejames (Hermit) on Jun 21, 2002 at 05:17 UTC
    Hi

    You should use Proc::ProcessTable :
    use Proc::ProcessTable; $t = new Proc::ProcessTable; foreach $p ( @{$t->table} ){ print "$p->pid -> $p->cmndline\n"; }

    HTH
    --
    zejames
Re: Listing Processes
by kvale (Monsignor) on Jun 21, 2002 at 05:23 UTC
    The CPAN module Proc::ProcessTable does all the parsing for you. Here is an example from the readme:
    # kill memory pigs use Proc::ProcessTable; $t = new Proc::ProcessTable; foreach $p ( @{$t->table} ){ if( $p->pctmem > 95 ){ $p->kill(9); } }

    -Mark
Re: Listing Processes
by Sinister (Friar) on Jun 21, 2002 at 13:36 UTC
    /me always does
    ps auxw | perl -l -e '@ps = map { chomp; [ split/\s\s+/ ]; } <STDIN>; +shift @ps; print $_->[1],"\t",$_->[$#{$_}] foreach @ps;'
    for that (because it is a shell alias of mine ... )

    But using a module there is just as usefull

    er formait hyarya.
    -- "Life is a house and the next tornado is never far away"
    -- "lovely by nature"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://176227]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found