sub interrupt { print "\n"; exit 0; }
$RPT = 15;
if (($LSOF = &isexec("../lsof")) eq "") { if (($LSOF = &isexec("lsof")) eq "") { print "can't execute $LSOF\n"; exit 1
}
}
$| = 1; $SIG{'INT'} = 'interrupt'; $proc = $files = $proto{'TCP'} = $proto{'UDP'} = 0;
$progress="/"; open(P, "$LSOF -nPF -r $RPT|") || die "can't open pipe to $LSOF\n";
while (<P>) {
chop;
if (/^m/) {
printf "%s Processes: %5d, Files: %6d, TCP: %6d, UDP: %6d\r",
$progress, $proc, $files, $proto{'TCP'}, $proto{'UDP'};
$proc = $files = $proto{'TCP'} = $proto{'UDP'} = 0;
if ($progress eq "/") { $progress = "\\"; } else { $progress = "/"; }
next;
}
if (/^p/) { $proc++; next; } if (/^f/) { $files++; next; } if (/^P(.*)/) { $proto{$1}++; next; } }
sub
isexec {
my ($path) = @_;
my ($i, @P, $PATH);
$path =~ s/^\s+|\s+$//g;
if ($path eq "") { return(""); }
if (($path =~ m if (-x $path) { return($path); }
return("");
}
$PATH = $ENV{PATH};
@P = split(":", $PATH);
for ($i = 0; $i <= $#P; $i++) {
if (-x "$P[$i]/$path") { return("$P[$i]/$path"); }
}
return("");
}