Kevin Old <[EMAIL PROTECTED]> wrote:
> 
> Basically all I do is pipe the input from ps into my perl program, and
> grep for cdlor.....but the path to perl has moved (long story) and the
> cdlor isn't printed in the command output from ps.

Can you explain?  

I can't see why changing the path to perl would break the "ps|grep"
command...

> #!/usr/bin/perl -w
> 
> $regex =
> '^\s{0,4}(\d{1,7})\s?(\d{2}:\d{2}:\d{2}|\s{0,3}\w{4}\d{2})\s{0,8}(\d{1,4}
> -?)?(\d{2}):(\d{2}):(\d{2})';

I prefer unpack() for this sort of thing -->

    #
    # this was for Solaris "top", but you get the idea
    #
    my @fields   = qw(pid psid user thr pri nice size res state time cpu cmd);
    my @template = qw(A6  A6   A9   A4  A4  A4   A6   A6  A7    A7   A7  A*);

    my %ret;
    while (<TOP>) {
        next if 1..5;

        my %proc;
        s/^\s+//, s/\s+$//
            for @[EMAIL PROTECTED] = unpack "@template", $_;

        $ret{$proc{pid}} = \%proc;
    }
    wantarray ? %ret : \%ret;
  }

> $pipe = open(PH, "ps -eo pid,stime,etime,comm \| grep cdlor |");
                                                ^
No need to escape the pipe.

[ snip parsing ]

> foreach $p (@pids) {
> 
>         $count{$p}++;
>         print $p . "\n";
> 
>         next if $count{$p} >= 2;
> 
>         @sysargs = ("kill", $p);
>         system("kill $p") == 0 and print "$p killed\n";
>         # or die "system @sysargs failed $?";

And here you could use the kill() function instead of system().  It's
faster -- doesn't spawn a subprocess -- and lets you do a better job
of error checking and reporting.


> }
> 

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to