Odd output from regex.

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
 
P

Paul Lalli

sunckell said:
[The same question he just posted]

Please don't do that. Usenet is not instanteous. Not seeing your
posted message immediately is not cause for posting the same message
again.

Paul Lalli
 
S

sunckell

Paul said:
sunckell said:
[The same question he just posted]

Please don't do that. Usenet is not instanteous. Not seeing your
posted message immediately is not cause for posting the same message
again.

Paul Lalli


I didn't.. Something happened with Opera when I hit submit. It hung
for a few minutes. I ended up having to kill it from the command line
to get it to stop.



sunckell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top