S
sunckell
Hello everyone,
I am getting some strange output from a regex. Wondering if anyone
can see what I am doing wrong. I am on a Solaris 8 server, running
perl 5.8
sub process_measurements{
my $cmd = "/usr/ucb/ps -auwwx";
my @trbl_pids;
open PS, "$cmd |" or die "Cannot open $cmd:$!\n";
while(<PS>){
next if /^USER/;
/^
(\w+) # user of process -- 1
\s+
(\d+) # pid of process -- 2
\s+
(\w+\.\w) # cpu percentage of process -- 3
\s+
(\w+\.\w) # memory percentage -- 4
\s+
(\w+) # virtual memory size -- 5
\s+
(\w+) # resident size of process -- 6
\s+
(\?|\w+\/\w+) # associated tty -- 7
\s+
(\w) # state of process -- 8
\s+
(.*) # start, time, and command -- 9
$/x or do
{
# this occurs when %MEM SZ ans RSS are wider than
# the column width and runs together. Which means
# they are higher usage processes. Will account
# for these separately.
warn "WARNING: line not in processable format:
$_\n";
my $user = $1;
my $pid = $2;
my $cpu = $3;
print "$pid $cpu $user\n";
push(@trbl_pids, $pid);
next;
}
}
close (PS);
print "TROUBLE: @trbl_pids\n";
}
Basically all I am doing is reading a ps output. When I print $user
and $pid I only get the first letter\digit of the field.
For example if root owns a process, I only get the letter r when I
print $user, where I should get root.
Anyone see my mistake, or am I over looking something in reading the
output?
Thanks,
sunckell
I am getting some strange output from a regex. Wondering if anyone
can see what I am doing wrong. I am on a Solaris 8 server, running
perl 5.8
sub process_measurements{
my $cmd = "/usr/ucb/ps -auwwx";
my @trbl_pids;
open PS, "$cmd |" or die "Cannot open $cmd:$!\n";
while(<PS>){
next if /^USER/;
/^
(\w+) # user of process -- 1
\s+
(\d+) # pid of process -- 2
\s+
(\w+\.\w) # cpu percentage of process -- 3
\s+
(\w+\.\w) # memory percentage -- 4
\s+
(\w+) # virtual memory size -- 5
\s+
(\w+) # resident size of process -- 6
\s+
(\?|\w+\/\w+) # associated tty -- 7
\s+
(\w) # state of process -- 8
\s+
(.*) # start, time, and command -- 9
$/x or do
{
# this occurs when %MEM SZ ans RSS are wider than
# the column width and runs together. Which means
# they are higher usage processes. Will account
# for these separately.
warn "WARNING: line not in processable format:
$_\n";
my $user = $1;
my $pid = $2;
my $cpu = $3;
print "$pid $cpu $user\n";
push(@trbl_pids, $pid);
next;
}
}
close (PS);
print "TROUBLE: @trbl_pids\n";
}
Basically all I am doing is reading a ps output. When I print $user
and $pid I only get the first letter\digit of the field.
For example if root owns a process, I only get the letter r when I
print $user, where I should get root.
Anyone see my mistake, or am I over looking something in reading the
output?
Thanks,
sunckell