Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Odd output from regex.

Reply
Thread Tools

Odd output from regex.

 
 
sunckell
Guest
Posts: n/a
 
      07-28-2006
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

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      07-28-2006
sunckell wrote:
> [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

 
Reply With Quote
 
 
 
 
sunckell
Guest
Posts: n/a
 
      07-28-2006

Paul Lalli wrote:
> sunckell wrote:
> > [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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very odd output from subprocess m Python 3 07-05-2010 10:01 PM
Help: Odd Output Amy Lee Perl Misc 6 01-27-2009 08:47 PM
odd output for an epson 3000 nozzle check cruzer Digital Photography 7 09-22-2007 02:43 AM
Odd behavior with odd code Michael Speer C Programming 33 02-18-2007 07:31 AM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments