1 /* vi: set sw=4 ts=4: */
3 * Mini kill/killall implementation for busybox
5 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
6 * Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 static const int KILL = 0;
36 static const int KILLALL = 1;
39 extern int kill_main(int argc, char **argv)
41 int whichApp, sig = SIGTERM, quiet;
45 /* Figure out what we are trying to do here */
46 whichApp = (strcmp(applet_name, "killall") == 0)? KILLALL : KILL;
54 /* Parse any options */
58 while (argc > 0 && **argv == '-') {
68 for(argv++; *argv; argv++) {
69 name = u_signal_names(*argv, &sig, -1);
75 for(sig=1; sig < NSIG; sig++) {
76 name = u_signal_names(0, &sig, 1);
77 if(name==NULL) /* unnamed */
79 col += printf("%2d) %-16s", sig, name);
91 name = u_signal_names(*argv, &sig, 0);
93 error_msg_and_die( "bad signal name: %s", *argv);
105 if (whichApp == KILL) {
106 /* Looks like they want to do a kill. Do that */
107 while (--argc >= 0) {
110 if (!isdigit(**argv))
111 perror_msg_and_die( "Bad PID");
112 pid = strtol(*argv, NULL, 0);
113 if (kill(pid, sig) != 0) {
114 perror_msg_and_die( "Could not kill pid '%d'", pid);
119 #ifdef CONFIG_KILLALL
121 int all_found = TRUE;
122 pid_t myPid=getpid();
123 /* Looks like they want to do a killall. Do that */
124 while (--argc >= 0) {
127 pidList = find_pid_by_name( *argv);
128 if (!pidList || *pidList<=0) {
133 error_msg_and_die( "%s: no process killed", *argv);
137 for(; pidList && *pidList!=0; pidList++) {
140 if (kill(*pidList, sig) != 0) {
144 perror_msg_and_die( "Could not kill pid '%d'", *pidList);
148 /* Note that we don't bother to free the memory
149 * allocated in find_pid_by_name(). It will be freed
150 * upon exit, so we can save a byte or two */