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
42 const struct signal_name signames[] = {
43 /* Everything, order not important */
71 {"VTALRM", SIGVTALRM},
73 /* everything except alpha */
77 #if defined(__sparc__) || defined(__alpha__) || defined(__mips__)
78 /* everthing except intel */
96 {"STKFLT", SIGSTKFLT},
98 {"UNUSED", SIGUNUSED},
103 extern int kill_main(int argc, char **argv)
105 int whichApp, sig = SIGTERM;
106 const char *appUsage;
109 /* Figure out what we are trying to do here */
110 whichApp = (strcmp(applet_name, "killall") == 0)? KILLALL : KILL;
111 appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
114 appUsage = kill_usage;
119 /* Parse any options */
123 while (argc > 0 && **argv == '-') {
129 const struct signal_name *s = signames;
131 while (s->name != 0) {
133 fprintf(stderr, "%2d) %-8s", s->number,
136 fprintf(stderr, "\n");
140 fprintf(stderr, "\n\n");
148 if (isdigit(**argv)) {
150 if (sig < 0 || sig >= NSIG)
158 const struct signal_name *s = signames;
160 while (s->name != 0) {
161 if (strcasecmp(s->name, *argv) == 0) {
181 if (whichApp == KILL) {
182 /* Looks like they want to do a kill. Do that */
183 while (--argc >= 0) {
186 if (!isdigit(**argv))
187 fatalError( "Bad PID: %s\n", strerror(errno));
188 pid = strtol(*argv, NULL, 0);
189 if (kill(pid, sig) != 0)
190 fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
196 int all_found = TRUE;
197 pid_t myPid=getpid();
198 /* Looks like they want to do a killall. Do that */
199 while (--argc >= 0) {
202 pidList = findPidByName( *argv);
205 errorMsg( "%s: no process killed\n", *argv);
208 for(; pidList && *pidList!=0; pidList++) {
211 if (kill(*pidList, sig) != 0)
212 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
214 /* Note that we don't bother to free the memory
215 * allocated in findPidByName(). It will be freed
216 * upon exit, so we can save a byte or two */
227 fatalError( "bad signal name: %s\n", *argv);