PERL:


PERL: - . 70


psgrep - ps

8 #


1.18. : psgrep 63

use strict;

# PS

my fieldnames = qw(FLAGS UID PID PPID PRI NICE SIZE RSS WCHAN STAT TTY TIME COMMAND),

# (

#  ps Linux)

my $fmt = cut2fmt(8, 14, 20, 26, 30, 34, 41, 47, 59, 63, 67, 72);

my %fields; #

die Thanatos unless ARGV; usage: $0 criterion ...

Each criterion is a Perl expression involving:

fieldnames

All criteria must be met for a line to be printed Thanatos

#  uid, size, UID, SIZE .


for my $name (fieldname) {

no strict 'refs';

name = *{lc $name} = sub () { $fields{$name} };

my $code = "sub is_desirable { " jom(" and ", @ARGV) ' } '; unless (eval $code.1) {

die "Error in code: $@\n\t$code\n";

open (PS, "ps wwaxl |") || die "cannot fork. $! ';

print scalar <PS>, # -
while (<PS> {

(5>fields{@fieldnames} = tnm(unpack($fmt, $_));

print if is_desirable(); # ,
}

close(PS) 11 die "ps failed!";

# sub cut2fmt {

my(@positions) = @_; my Stemplate = ' '; my Slastpos = 1; foreach $place(positions) {

$template .= "A" . ($place - $lastpos) . " "; Slastpos = $place; } Stemplate .= "A*";

&


64 1

1.6 ()

return $template;

sub trim {

my out = @_; for (@out) <


s/\s+$//; } return wantarray ? @out :


Dut[0];


# .


#123456789012345678901234567890123456789012345678901234567890123456789012345

1

26 30 34 I I I