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-2003 by Erik Andersen <andersen@codepoet.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;
38 extern int kill_main(int argc, char **argv)
40 int whichApp, signo = SIGTERM, quiet = 0;
45 /* Figure out what we are trying to do here */
46 whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
51 /* Parse any options */
55 if(argv[1][0] != '-'){
61 /* The -l option, which prints out signal names. */
62 if(argv[1][1]=='l' && argv[1][2]=='\0'){
64 /* Print the whole signal list */
66 for(signo=1; signo < NSIG; signo++) {
67 name = u_signal_names(0, &signo, 1);
68 if(name==NULL) /* unnamed */
70 col += printf("%2d) %-16s", signo, name);
79 for(argv++; *argv; argv++) {
80 name = u_signal_names(*argv, &signo, -1);
85 /* If they specified -l, were all done */
89 /* The -q quiet option */
90 if(argv[1][1]=='q' && argv[1][2]=='\0'){
94 if(argv[1][0] != '-'){
99 if(!u_signal_names(argv[1]+1, &signo, 0))
100 bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
106 if (whichApp == KILL) {
107 /* Looks like they want to do a kill. Do that */
108 while (--argc >= 0) {
111 if (!isdigit(**argv))
112 bb_error_msg_and_die( "Bad PID '%s'", *argv);
113 pid = strtol(*argv, NULL, 0);
114 if (kill(pid, signo) != 0) {
115 bb_perror_msg( "Could not kill pid '%d'", pid);
122 #ifdef CONFIG_KILLALL
124 pid_t myPid=getpid();
125 /* Looks like they want to do a killall. Do that */
126 while (--argc >= 0) {
129 pidList = find_pid_by_name(*argv);
130 if (!pidList || *pidList<=0) {
133 bb_error_msg( "%s: no process killed", *argv);
137 for(pl = pidList; *pl !=0 ; pl++) {
140 if (kill(*pl, signo) != 0) {
143 bb_perror_msg( "Could not kill pid '%ld'", *pl);