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-2004 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
38 extern int kill_main(int argc, char **argv)
40 int whichApp, signo = SIGTERM;
46 /* Figure out what we are trying to do here */
47 whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
52 /* Parse any options */
56 if(argv[1][0] != '-'){
62 /* The -l option, which prints out signal names. */
63 if(argv[1][1]=='l' && argv[1][2]=='\0'){
65 /* Print the whole signal list */
67 for(signo=1; signo < NSIG; signo++) {
68 name = u_signal_names(0, &signo, 1);
69 if(name==NULL) /* unnamed */
71 col += printf("%2d) %-16s", signo, name);
80 for(argv++; *argv; argv++) {
81 name = u_signal_names(*argv, &signo, -1);
86 /* If they specified -l, were all done */
91 /* The -q quiet option */
92 if(whichApp != KILL && argv[1][1]=='q' && argv[1][2]=='\0'){
96 if(argc<2 || argv[1][0] != '-'){
102 if(!u_signal_names(argv[1]+1, &signo, 0))
103 bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
109 /* Pid or name required */
113 if (whichApp == KILL) {
114 /* Looks like they want to do a kill. Do that */
115 while (--argc >= 0) {
118 if (!isdigit(**argv) && **argv != '-')
119 bb_error_msg_and_die( "Bad PID '%s'", *argv);
120 pid = strtol(*argv, NULL, 0);
121 if (kill(pid, signo) != 0) {
122 bb_perror_msg( "Could not kill pid '%d'", pid);
129 #ifdef CONFIG_KILLALL
131 pid_t myPid=getpid();
132 /* Looks like they want to do a killall. Do that */
133 while (--argc >= 0) {
136 pidList = find_pid_by_name(*argv);
137 if (!pidList || *pidList<=0) {
140 bb_error_msg( "%s: no process killed", *argv);
144 for(pl = pidList; *pl !=0 ; pl++) {
147 if (kill(*pl, signo) != 0) {
150 bb_perror_msg( "Could not kill pid '%ld'", *pl);