summaryrefslogtreecommitdiffstats
path: root/usr.bin/killall
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1995-06-25 18:08:27 +0000
committerjoerg <joerg@FreeBSD.org>1995-06-25 18:08:27 +0000
commitc2059974cbc6f0ace66503479f929a3014f00f27 (patch)
treeb7a73d96ed5457a0e0785e136fa0bfea82f6e500 /usr.bin/killall
downloadFreeBSD-src-c2059974cbc6f0ace66503479f929a3014f00f27.zip
FreeBSD-src-c2059974cbc6f0ace66503479f929a3014f00f27.tar.gz
Our Perl oracle hit again: Wolfram Schneider's killall utility.
Kills processes by name instead of by UID. (Man page by me.) Submitted by: wosch@cs.tu-berlin.de (Wolfram Schneider)
Diffstat (limited to 'usr.bin/killall')
-rw-r--r--usr.bin/killall/Makefile7
-rw-r--r--usr.bin/killall/killall.1130
-rwxr-xr-xusr.bin/killall/killall.pl103
3 files changed, 240 insertions, 0 deletions
diff --git a/usr.bin/killall/Makefile b/usr.bin/killall/Makefile
new file mode 100644
index 0000000..17cfc53
--- /dev/null
+++ b/usr.bin/killall/Makefile
@@ -0,0 +1,7 @@
+MAN1= killall.1
+
+beforeinstall:
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${.CURDIR}/killall.pl ${DESTDIR}${BINDIR}/killall
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/killall/killall.1 b/usr.bin/killall/killall.1
new file mode 100644
index 0000000..f08a649
--- /dev/null
+++ b/usr.bin/killall/killall.1
@@ -0,0 +1,130 @@
+.\" Copyright (C) 1995 by Joerg Wunsch, Dresden
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
+.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $Id$
+.\"
+.Dd June 25, 1995
+.Os FreeBSD 2.2
+.Dt KILLALL 1
+.Sh NAME
+.Nm killall
+.Nd kill processes by name
+.Sh SYNOPSIS
+.Nm killall
+.Op Fl d \&| Ns Fl v
+.Op Fl h \&| Ns Fl \&?
+.Op Fl help
+.Op Fl l
+.Op Fl m
+.Op Fl s
+.Op Fl SIGNAL
+.Ar procname
+.Sh DESCRIPTION
+.Nm Killall
+kills processes selected by name, as opposed to the selection by pid
+as done by
+.Xr kill 1 .
+By default, it will send a
+.Dv TERM
+signal to all processes with an effective UID identical to the
+caller of
+.Nm
+that match the name
+.Ar procname .
+The super-user is allowed to kill any process.
+.Pp
+The options are as follows:
+.Bl -tag -width 10n -offset indent
+.It Fl d \&| Ns Fl v
+Be more verbose about what will be done. For a single
+.Fl d
+option, a list of the processes that will be sent the signal will be
+printed, or a message indicating that no matching processes have been
+found. If the option
+.Fl d
+has been specified at least twice, the effective UID, PID, and name
+of all processes found in
+.Xr procfs 5
+will be listed in addition.
+.It Fl h \&| Ns Fl \&?
+.It Fl help
+Give a help on the command usage and exit.
+.It Fl l
+List the names of the available signals and exit, like in
+.Xr kill 1 .
+.It Fl m
+Match the argument
+.Ar procname
+as a (case insensitive) regular expression against the names
+of processes found in
+.Xr procfs 5 .
+CAUTION! This is dangerous, a single dot will match any process
+running under the effective UID of the caller. The regular expression
+syntax in effect is that used by
+.Xr perl 1 .
+.It Fl s
+Show only what would be done, but do net send any signal.
+.It Fl SIGNAL
+Send a different signal instead of the default
+.Dv TERM .
+The signal may be specified either as a name
+.Pq with \&or without a leading Dv SIG ,
+or numerically.
+.El
+
+.Sh DIAGNOSTICS
+The
+.Nm
+command will respond with a short usage message and exit with a status
+of 2 in case of a command error. A status of 1 will be returned if
+either no matching process has been found or not all processes have
+been signalled succesfully. Otherwise, a status of 0 will be
+returned.
+.Pp
+Diagnostic messages will only be printed if requested by
+.Fl d
+options.
+.Sh SEE ALSO
+.Xr kill 1 ,
+.Xr perl 1 ,
+.Xr procfs 5 .
+.Sh HISTORY
+The
+.Nm
+command appeared in FreeBSD 2.2. It has been featured after the
+.Nm
+command as available on other platforms.
+.Sh AUTHOR
+The program has been contributed by Wolfram Schneider, this manual
+page has been written by
+.if n Joerg Wunsch.
+.if t J\(:org Wunsch.
+.Sh BUGS
+Due to limitations in the current implementation of
+.Xr procfs 5 ,
+it is only possible to figure out the effective UID of a process.
+Hence it is impossible to find processes that run setuid, thus a
+regular user will not be able to use
+.Nm
+to send signals to such processes.
diff --git a/usr.bin/killall/killall.pl b/usr.bin/killall/killall.pl
new file mode 100755
index 0000000..e6a58b5
--- /dev/null
+++ b/usr.bin/killall/killall.pl
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+#
+# Copyright (c) 1995 Wolfram Schneider <wosch@cs.tu-berlin.de>
+# All rights reserved. Alle Rechte vorbehalten.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by Wolfram Schneider
+# 4. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# killall - kill all processes
+#
+# Note: work only with effective uid due the limit of procfs
+# (eg. not with suid programs)
+#
+# $Id: killall,v 1.2 1995/06/24 11:12:38 w Exp w $
+#
+
+$ENV{'PATH'} = "/bin:/usr/bin";
+$procfs = '/proc';
+$signal = 'SIGTERM'; # default signal for kill
+$debug = 0;
+$match = 0; # 0 match exactly program name
+$show = 0;
+
+$PROC_NAME = 0 + $[;
+$PROC_EUID = 11 + $[;
+
+sub usage {
+ $! = 2;
+ die "killall [-v] [-?|-help] [-l] [-m] [-s] [-SIGNAL] program\n";
+}
+
+while ($_ = $ARGV[0], /^-/) {
+ shift @ARGV;
+ if (/^--$/) { $_ = $ARGV[0]; last }
+ elsif (/^-[vd]$/) { $debug++ }
+ elsif (/^-(h|help|\?)$/) { do usage }
+ elsif (/^-l$/) { exec 'kill', '-l' }
+ elsif (/^-m$/) { $match = 1 }
+ elsif (/^-s$/) { $show = 1 }
+ elsif (/^-([A-Za-z]+|[0-9]+)$/) { $signal = $1 }
+}
+
+$program = $_; &usage unless $program;
+
+die "Maybe $procfs is not mounted\n" unless -e "$procfs/0/status";
+opendir(PROCFS, "$procfs") || die "$procfs $!\n";
+
+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 $proc[$PROC_NAME] $proc[$PROC_EUID]\n", $pid
+ if $debug > 1;
+
+ if (($proc[$PROC_NAME] eq $program ||
+ ($match && $proc[$PROC_NAME] =~ /$program/i)
+ ) && # test program name
+ ($proc[$PROC_EUID] eq $< || $< == 0)) { # test uid
+ push(@kill, "$pid");
+ }
+ }
+ close STATUS;
+}
+closedir PROCFS;
+
+if ($#kill < 0) { # nothing found
+ print "No matching process.\n" if $debug || $show;
+ exit(1);
+}
+$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;
+
+$cnt = kill ($signal, @kill) unless $show; # kill processes
+exit(0) if $show || $cnt == $#kill + 1;
+exit(1);
OpenPOWER on IntegriCloud