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 = $tcp = $udp = 0;
$progress="/";
open(P, "$LSOF -nPF0 -r $RPT|") || die "can't open pipe to $LSOF\n";
LSOF_LINE:
while (<P>) {
chop;
if (/^m/) {
printf "%s Processes: %5d, Files: %6d, TCP: %6d, UDP: %6d\r",
$progress, $proc, $files, $tcp, $udp;
$proc = $files = $tcp = $udp = 0;
if ($progress eq "/") { $progress = "\\"; } else { $progress = "/"; }
next LSOF_LINE;
}
if (/^p/) {
$proc++;
next LSOF_LINE;
}
if (/^f/) {
$files++;
@F = split("\0", $_, 999);
foreach $i (0 .. ($#F - 1)) {
if ($F[$i] =~ /^P(.*)/) {
if ($1 eq "TCP") { $tcp++; }
elsif ($1 eq "UDP") { $udp++; }
next LSOF_LINE;
}
}
}
}
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("");
}