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
41 const struct signal_name signames[] = {
42 /* Everything, order not important */
70 {"VTALRM", SIGVTALRM},
72 /* everything except alpha */
76 #if defined(__sparc__) || defined(__alpha__) || defined(__mips__)
77 /* everthing except intel */
95 {"STKFLT", SIGSTKFLT},
97 {"UNUSED", SIGUNUSED},
102 extern int kill_main(int argc, char **argv)
104 int whichApp, sig = SIGTERM;
105 const char *appUsage;
108 /* Figure out what we are trying to do here */
109 whichApp = (strcmp(applet_name, "killall") == 0)? KILLALL : KILL;
110 appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
113 appUsage = kill_usage;
118 /* Parse any options */
122 while (argc > 0 && **argv == '-') {
128 const struct signal_name *s = signames;
130 while (s->name != 0) {
132 fprintf(stderr, "%2d) %-8s", s->number,
135 fprintf(stderr, "\n");
139 fprintf(stderr, "\n\n");
147 if (isdigit(**argv)) {
149 if (sig < 0 || sig >= NSIG)
157 const struct signal_name *s = signames;
159 while (s->name != 0) {
160 if (strcasecmp(s->name, *argv) == 0) {
180 if (whichApp == KILL) {
181 /* Looks like they want to do a kill. Do that */
182 while (--argc >= 0) {
185 if (!isdigit(**argv))
186 fatalError( "Bad PID: %s\n", strerror(errno));
187 pid = strtol(*argv, NULL, 0);
188 if (kill(pid, sig) != 0)
189 fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
195 int all_found = TRUE;
196 pid_t myPid=getpid();
197 /* Looks like they want to do a killall. Do that */
198 while (--argc >= 0) {
201 pidList = findPidByName( *argv);
204 errorMsg( "%s: no process killed\n", *argv);
207 for(; pidList && *pidList!=0; pidList++) {
210 if (kill(*pidList, sig) != 0)
211 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
213 /* Note that we don't bother to free the memory
214 * allocated in findPidByName(). It will be freed
215 * upon exit, so we can save a byte or two */
226 fatalError( "bad signal name: %s\n", *argv);