Odd output from regex.

Discussion in 'Perl Misc' started by sunckell, Jul 28, 2006.

  1. sunckell

    sunckell Guest

    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
    sunckell, Jul 28, 2006
    #1
    1. Advertising

  2. sunckell

    Paul Lalli Guest

    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
    Paul Lalli, Jul 28, 2006
    #2
    1. Advertising

  3. sunckell

    sunckell Guest

    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
    sunckell, Jul 28, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Speer

    Odd behavior with odd code

    Michael Speer, Feb 16, 2007, in forum: C Programming
    Replies:
    33
    Views:
    1,087
    Richard Heathfield
    Feb 18, 2007
  2. Replies:
    2
    Views:
    385
    Phlip
    Aug 2, 2006
  3. Replies:
    3
    Views:
    748
    Reedick, Andrew
    Jul 1, 2008
  4. Dan Wilkin
    Replies:
    1
    Views:
    258
    robic0
    Jul 17, 2006
  5. Mintcake

    Odd regex behavior

    Mintcake, Oct 1, 2007, in forum: Perl Misc
    Replies:
    9
    Views:
    138
    Brian McCauley
    Oct 4, 2007
Loading...

Share This Page