diff options
author | smpatel <smpatel@FreeBSD.org> | 1996-05-30 22:04:09 +0000 |
---|---|---|
committer | smpatel <smpatel@FreeBSD.org> | 1996-05-30 22:04:09 +0000 |
commit | 49058140a15d8d8b2b82bda5d8c2385c28e2cf48 (patch) | |
tree | 0006e553d136e15d5afdd1ac128dd382e78d68ac /usr.bin | |
parent | 63f8b4ca8ea7fe7b74ac1788700fe1f131be244e (diff) | |
download | FreeBSD-src-49058140a15d8d8b2b82bda5d8c2385c28e2cf48.zip FreeBSD-src-49058140a15d8d8b2b82bda5d8c2385c28e2cf48.tar.gz |
Allow multiple process names to kill (i.e. 'killall ftpd inetd httpd')
Submitted by: smpatel, wosch
Reviewed by: wosch
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/killall/killall.1 | 4 | ||||
-rwxr-xr-x | usr.bin/killall/killall.pl | 87 |
2 files changed, 48 insertions, 43 deletions
diff --git a/usr.bin/killall/killall.1 b/usr.bin/killall/killall.1 index df4cada..3307f00 100644 --- a/usr.bin/killall/killall.1 +++ b/usr.bin/killall/killall.1 @@ -22,7 +22,7 @@ .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: killall.1,v 1.4 1996/02/03 21:50:20 wosch Exp $ +.\" $Id: killall.1,v 1.3 1996/02/03 22:52:26 wosch Exp $ .\" .Dd June 25, 1995 .Os FreeBSD 2.2 @@ -39,7 +39,7 @@ .Op Fl m .Op Fl s .Op Fl SIGNAL -.Ar procname +.Ar procname ... .Sh DESCRIPTION .Nm Killall kills processes selected by name, as opposed to the selection by pid diff --git a/usr.bin/killall/killall.pl b/usr.bin/killall/killall.pl index b37735f..a9deb9e 100755 --- a/usr.bin/killall/killall.pl +++ b/usr.bin/killall/killall.pl @@ -30,7 +30,7 @@ # # killall - kill processes by name # -# $Id: killall.pl,v 1.3 1996/02/03 22:52:27 wosch Exp $ +# $Id: $ # $ENV{'PATH'} = '/bin:/usr/bin'; # security @@ -47,7 +47,7 @@ $PROC_RUID = 12; sub usage { $! = 2; - die "killall [-?|-help] [-d] [-l] [-m] [-s] [-SIGNAL] program\n"; + die "killall [-?|-help] [-d] [-l] [-m] [-s] [-SIGNAL] procname ...\n"; } $id = $<; # real uid of this process / your id @@ -63,49 +63,55 @@ while ($_ = $ARGV[0], /^-/) { elsif (/^-/) { &usage } } -$program = $_; &usage unless $program; - - +&usage if $#ARGV < 0; # no arguments die "Maybe $procfs is not mounted\n" unless -e "$procfs/0/status"; -opendir(PROCFS, "$procfs") || die "$procfs $!\n"; -print " PID EUID RUID COMMAND\n" if $debug > 1; - -# 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 - - 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; - - if ( # match program name - ($proc[$PROC_NAME] eq $program || - ($match && $proc[$PROC_NAME] =~ /$programMatch/oi) - ) && - # id test - ($proc[$PROC_EUID] eq $id || # effective uid - $proc[$PROC_RUID] eq $id || # real uid - !$id)) # root - { - push(@kill, $pid); - } + +while ($program = $ARGV[0]) { + shift @ARGV; + $thiskill = 0; + + opendir(PROCFS, "$procfs") || die "$procfs $!\n"; + print " PID EUID RUID COMMAND\n" if $debug > 1; + + # 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 + + 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; + + if ( # match program name + ($proc[$PROC_NAME] eq $program || + ($match && $proc[$PROC_NAME] =~ /$programMatch/oi) + ) && + # id test + ($proc[$PROC_EUID] eq $id || # effective uid + $proc[$PROC_RUID] eq $id || # real uid + !$id)) # root + { + push(@kill, $pid); + $thiskill++; + } + } + close STATUS; } - close STATUS; -} -closedir PROCFS; + closedir PROCFS; -if ($#kill < 0) { # nothing found - warn "No matching processes ``$program''.\n"; - exit(1); + # nothing found + warn "No matching processes ``$program''\n" unless $thiskill; } +# nothing found +exit(1) if $#kill < 0; + $signal =~ y/a-z/A-Z/; # signal name in upper case $signal =~ s/^SIG//; # strip a leading SIG if present print "kill -$signal @kill\n" if $debug || $show; @@ -113,4 +119,3 @@ print "kill -$signal @kill\n" if $debug || $show; $cnt = kill ($signal, @kill) unless $show; # kill processes exit(0) if $show || $cnt == $#kill + 1; exit(1); - |