Next | Program Repair Shop | 68 |
Subject: alternatives to ps command
Message-Id: <7fe42fcd.0109240201.7a6f98c2@posting.google.com>
my $ps = `ps -fu$user`;
# convert our scalar $ps into an array, break on \n
my @aps = split /\n/, $ps;
# loop each real processes
foreach my $iaps (@aps) {
# these are the only elements we require
my ($stime, $time, $cmd);
# loop each possible process type
foreach my $p (@processes) {
# match the elements we require
if ($iaps =~ m/^\s+\w+\s+\d+\s+\d+\s+\d+\s+([\d:]+)\s.+\s([\d:]+)\s(.+)
$/) {
# save the values we have matched from above regex
$cmd = $3; $stime = $1; $time = $2;
...
I suggest:
for my $iaps (`ps -fu$user | tail +1`) { my ($user, $pid, $ppid, $cpu, $stime, $tty, $time, $cmd) = split /\s+/, $iaps, 8; foreach my $p (@processes) { ...
Note the 8 in the split to prevent $cmd from being split
Next | Copyright © 2006 M. J. Dominus |