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>.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 static const int KILL = 0;
35 static const int KILLALL = 1;
38 extern int kill_main(int argc, char **argv)
40 int whichApp, sig = SIGTERM;
44 /* Figure out what we are trying to do here */
45 whichApp = (strcmp(applet_name, "killall") == 0)? KILLALL : KILL;
52 /* Parse any options */
56 while (argc > 0 && **argv == '-') {
61 for(argv++; *argv; argv++) {
62 name = u_signal_names(*argv, &sig, -1);
68 for(sig=1; sig < NSIG; sig++) {
69 name = u_signal_names(0, &sig, 1);
70 if(name==NULL) /* unnamed */
72 col += printf("%2d) %-16s", sig, name);
84 name = u_signal_names(*argv, &sig, 0);
86 error_msg_and_die( "bad signal name: %s", *argv);
98 if (whichApp == KILL) {
99 /* Looks like they want to do a kill. Do that */
100 while (--argc >= 0) {
103 if (!isdigit(**argv))
104 perror_msg_and_die( "Bad PID");
105 pid = strtol(*argv, NULL, 0);
106 if (kill(pid, sig) != 0)
107 perror_msg_and_die( "Could not kill pid '%d'", pid);
113 int all_found = TRUE;
114 pid_t myPid=getpid();
115 /* Looks like they want to do a killall. Do that */
116 while (--argc >= 0) {
119 pidList = find_pid_by_name( *argv);
120 if (!pidList || *pidList<=0) {
122 error_msg_and_die( "%s: no process killed", *argv);
125 for(; pidList && *pidList!=0; pidList++) {
128 if (kill(*pidList, sig) != 0)
129 perror_msg_and_die( "Could not kill pid '%d'", *pidList);
131 /* Note that we don't bother to free the memory
132 * allocated in find_pid_by_name(). It will be freed
133 * upon exit, so we can save a byte or two */
136 if (all_found == FALSE)