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 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
24 int kill_main(int argc, char **argv)
26 int whichApp, signo = SIGTERM;
32 /* Figure out what we are trying to do here */
33 whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
38 /* Parse any options */
42 if(argv[1][0] != '-'){
48 /* The -l option, which prints out signal names. */
49 if(argv[1][1]=='l' && argv[1][2]=='\0'){
51 /* Print the whole signal list */
53 for(signo=1; signo < NSIG; signo++) {
54 name = u_signal_names(0, &signo, 1);
55 if(name==NULL) /* unnamed */
57 col += printf("%2d) %-16s", signo, name);
66 for(argv++; *argv; argv++) {
67 name = u_signal_names(*argv, &signo, -1);
72 /* If they specified -l, were all done */
77 /* The -q quiet option */
78 if(whichApp != KILL && argv[1][1]=='q' && argv[1][2]=='\0'){
82 if(argc<2 || argv[1][0] != '-'){
88 if(!u_signal_names(argv[1]+1, &signo, 0))
89 bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
95 /* Pid or name required */
99 if (whichApp == KILL) {
100 /* Looks like they want to do a kill. Do that */
101 while (--argc >= 0) {
104 if (!isdigit(**argv) && **argv != '-')
105 bb_error_msg_and_die( "Bad PID '%s'", *argv);
106 pid = strtol(*argv, NULL, 0);
107 if (kill(pid, signo) != 0) {
108 bb_perror_msg( "Could not kill pid '%d'", pid);
115 #ifdef CONFIG_KILLALL
117 pid_t myPid=getpid();
118 /* Looks like they want to do a killall. Do that */
119 while (--argc >= 0) {
122 pidList = find_pid_by_name(*argv);
123 if (!pidList || *pidList<=0) {
126 bb_error_msg( "%s: no process killed", *argv);
130 for(pl = pidList; *pl !=0 ; pl++) {
133 if (kill(*pl, signo) != 0) {
136 bb_perror_msg( "Could not kill pid '%ld'", *pl);