1 /* vi: set sw=4 ts=4: */
3 * Mini kill 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
33 static const char *kill_usage =
34 "kill [-signal] process-id [process-id ...]\n\n"
35 "Send a signal (default is SIGTERM) to the specified process(es).\n\n"
36 "Options:\n" "\t-l\tList all signal names and numbers.\n\n";
44 const struct signal_name signames[] = {
54 #if defined(__sparc__) || defined(__alpha__)
61 #if defined(__sparc__) || defined(__alpha__)
67 #if defined(__sparc__) || defined(__alpha__)
75 #if defined(__sparc__) || defined(__alpha__)
89 {"VTALRM", SIGVTALRM},
100 {"STKFLT", SIGSTKFLT},
110 {"VTALRM", SIGVTALRM},
116 {"UNUSED", SIGUNUSED},
121 extern int kill_main(int argc, char **argv)
127 /* Parse any options */
131 while (argc > 0 && **argv == '-') {
137 const struct signal_name *s = signames;
139 while (s->name != 0) {
141 fprintf(stderr, "%2d) %-8s", s->number,
144 fprintf(stderr, "\n");
148 fprintf(stderr, "\n\n");
156 if (isdigit(**argv)) {
158 if (sig < 0 || sig >= NSIG)
166 const struct signal_name *s = signames;
168 while (s->name != 0) {
169 if (strcasecmp(s->name, *argv) == 0) {
189 while (--argc >= 0) {
192 char pidpath[20] = "/proc/";
194 if (!isdigit(**argv)) {
195 fprintf(stderr, "bad PID: %s\n", *argv);
199 snprintf(pidpath, 20, "/proc/%s/stat", *argv);
200 if (stat(pidpath, &statbuf) != 0) {
201 fprintf(stderr, "kill: (%d) - No such pid\n", pid);
204 fprintf(stderr, "sig = %d\n", sig);
205 if (kill(pid, sig) != 0) {
215 fprintf(stderr, "bad signal name: %s\n", *argv);