Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: obtaining pid's in Unix environment

by mojotoad (Monsignor)
on Nov 18, 2004 at 15:03 UTC ( [id://408782]=note: print w/replies, xml ) Need Help??


in reply to obtaining pid's in Unix environment

Here's more of a perlish way to get what you want, which is what you seemed to be asking for:
open(PS, "ps -ef |") or die "Problem invoking 'ps': $!\n"; while (<PS>) { next unless /$version/ && /online/; my($pid) = (split)[2]; print "pid $pid\n"; } close(PS);

Cheers,
Matt

P.S. If you want to access the value of $pid outside of the while loop, drop the 'my' but keep the parens, but that will break if there's more than one match:

while (<PS>) { next unless /$version/ && /online/; ($pid) = (split)[2]; } print "pid $pid\n";

Log In?
Username:
Password:

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

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

    No recent polls found