sigar/exp/proc_stat.pl

22 lines
406 B
Perl
Raw Permalink Normal View History

#!perl
use strict;
#examine specific field from /proc/*/stat
my $field = shift;
2008-05-09 12:06:35 +08:00
my $proc = $ENV{PROC_FS} || "/proc";
opendir DH, $proc or die;
chdir $proc;
local $/;
while (my $pid = readdir DH) {
next unless $pid =~ /^\d+$/;
open FH, "$pid/stat" or next;
my $data = <FH>;
close FH;
my(@fields) = split /\s+/, $data;
print "$pid $fields[1] -> $fields[$field]\n";
}
closedir DH;