dotfiles/bin/ps_warriors
michener 83d40113d2 First import
git-svn-id: http://photonzero.com/dotfiles/trunk@1 23f722f6-122a-0410-8cef-c75bd312dd78
2007-03-19 06:17:17 +00:00

24 lines
466 B
Perl
Executable file

#!/usr/bin/perl
$cnt = ($ARGV[0] eq "-n" && $ARGV[1] =~ /^\d+$/) ? $ARGV[1] : 20;
opendir(PROC, "/proc");
while ($_ = readdir(PROC)) {
next if (/curproc/);
$id = (stat("/proc/$_"))[4];
next unless defined $id;
$procs{$id}++;
}
closedir(PROC);
$procs{$<}--;
@ids = reverse sort { $procs{$a} <=> $procs{$b} } keys(%procs);
format STDOUT =
@>>> @<<<<<<<
$procs{$id}, (getpwuid($id))[0]
.
for $id (($cnt) ? @ids[0..($cnt-1)] : @ids) {
write;
}