diff options
author | wosch <wosch@FreeBSD.org> | 1998-01-01 17:24:43 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1998-01-01 17:24:43 +0000 |
commit | 4da8ac54d4f34432f621e6af77663ae9ec429776 (patch) | |
tree | a098803dc59d960a08c9b57621941c428ff4cf74 /usr.bin/killall | |
parent | 017d9a924293d9d5920b1bc1f37a5203fb6e1d28 (diff) | |
download | FreeBSD-src-4da8ac54d4f34432f621e6af77663ae9ec429776.zip FreeBSD-src-4da8ac54d4f34432f621e6af77663ae9ec429776.tar.gz |
Re-order the for loop for multiple procnames. This decrease the
system load and makes a
killall ppp rlogin ftp ssh ping traceroute telnet
a lot faster.
Remove duplicated pid's before killing (killall lynx lynx).
Diffstat (limited to 'usr.bin/killall')
-rwxr-xr-x | usr.bin/killall/killall.pl | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/usr.bin/killall/killall.pl b/usr.bin/killall/killall.pl index 2e8dc66..098f08b 100755 --- a/usr.bin/killall/killall.pl +++ b/usr.bin/killall/killall.pl @@ -26,7 +26,7 @@ # # killall - kill processes by name # -# $Id$ +# $Id: killall.pl,v 1.8 1997/02/22 19:55:24 peter Exp $ $ENV{'PATH'} = '/bin:/usr/bin'; # security @@ -62,49 +62,53 @@ while ($_ = $ARGV[0], /^-/) { &usage if $#ARGV < 0; # no arguments die "Maybe $procfs is not mounted\n" unless -e "$procfs/0/status"; -while ($program = $ARGV[0]) { - shift @ARGV; - $thiskill = 0; +opendir(PROCFS, "$procfs") || die "$procfs $!\n"; +print " PID EUID RUID COMMAND\n" if $debug > 1; - opendir(PROCFS, "$procfs") || die "$procfs $!\n"; - print " PID EUID RUID COMMAND\n" if $debug > 1; +undef %pidu; +undef %thiskill; - # quote meta characters - ($programMatch = $program) =~ s/(\W)/\\$1/g; +foreach (sort{$a <=> $b} grep(/^[0-9]/, readdir(PROCFS))) { + $status = "$procfs/$_/status"; + $pid = $_; + next if $pid == $$; # don't kill yourself - foreach (sort{$a <=> $b} grep(/^[0-9]/, readdir(PROCFS))) { - $status = "$procfs/$_/status"; - $pid = $_; - next if $pid == $$; # don't kill yourself + open(STATUS, "$status") || next; # process maybe already terminated + while(<STATUS>) { + @proc = split; - open(STATUS, "$status") || next; # process maybe already terminated - while(<STATUS>) { - @proc = split; + printf "%5d %5d %5d %s\n", $pid, $proc[$PROC_EUID], + $proc[$PROC_RUID], $proc[$PROC_NAME] if $debug > 1; - printf "%5d %5d %5d %s\n", $pid, $proc[$PROC_EUID], - $proc[$PROC_RUID], $proc[$PROC_NAME] if $debug > 1; + foreach $program (@ARGV) { + # quote meta characters + ($programMatch = $program) =~ s/(\W)/\\$1/g if $match; if ( # match program name ($proc[$PROC_NAME] eq $program || - ($match && $proc[$PROC_NAME] =~ /$programMatch/oi) + ($match && $proc[$PROC_NAME] =~ /$programMatch/i) ) && # id test ($proc[$PROC_EUID] eq $id || # effective uid $proc[$PROC_RUID] eq $id || # real uid !$id)) # root { - push(@kill, $pid); - $thiskill++; + push(@kill, $pid) if !$pidu{"$pid"}; + $pidu{"$pid"} = $pid; + $thiskill{"$program"}++; } - } - close STATUS; + } } - closedir PROCFS; + close STATUS; +} +closedir PROCFS; - # nothing found - warn "No matching processes ``$program''\n" unless $thiskill; +# nothing found +foreach $program (@ARGV) { + warn "No matching processes ``$program''\n" unless $thiskill{"$program"}; } + # nothing found exit(1) if $#kill < 0; |