Parsing results of ps?

From: Marv (marv_at_stevens.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 03:31:53 GMT

Hello,

I'm a perl beginner and having trouble with what would appear like a
simple task.

I need to capture PID number from each line into a variable while in a
loop. The help I need is how to get to split each line of the output
so that I get the PID number regardless of how many digits long it is.
The output of ps -x gives me the pid number in the first column,
however it seems to be right justified in this column as such:

 2193 ? S blahblah blah
26127 pts/0 S blahblah blah
 4513 ? S blahblah blah

So when I try to do a split using a space as the delimiter some of the
variables end up empty.

How could I do this so that I always end up with the PID number?

Thanks,
Marv



Relevant Pages

  • Re: Parsing results of ps?
    ... > I'm a perl beginner and having trouble with what would appear like a ... > so that I get the PID number regardless of how many digits long it is. ... > The output of ps -x gives me the pid number in the first column, ...
    (comp.lang.perl.misc)
  • Re: Parsing results of ps?
    ... > I'm a perl beginner and having trouble with what would appear like a ... > so that I get the PID number regardless of how many digits long it is. ... > The output of ps -x gives me the pid number in the first column, ...
    (comp.lang.perl.misc)
  • Forking HTTP Daemon - Problem
    ... I'm having some trouble trying to get this simple forking http daemon to ... of error messages every few seconds. ... next if $pid; ...
    (comp.lang.perl)
  • Re: Help tracking down a naughty process
    ... In the last episode, Adam McLaurin said: ... > Trouble is, by the time I go to check what pid 37735 is, it's already ...
    (freebsd-questions)
  • Re: R[X,Y] polynomial ring
    ... Sorry about the inconsistant use of x and X ... have another little query ... Am trying to show that Zis not a PID ... I'm having trouble actually constructing a non principle ideal ...
    (sci.math)