2 * Mini kill implementation for busybox
4 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
33 "Send a signal (default is SIGTERM) to the specified process(es).\n\n"
35 "\t-l\tList all signal names and numbers.\n\n";
43 const struct signal_name signames[] = {
53 #if defined(__sparc__) || defined(__alpha__)
60 #if defined(__sparc__) || defined(__alpha__)
66 #if defined(__sparc__) || defined(__alpha__)
74 #if defined(__sparc__) || defined(__alpha__)
88 {"VTALRM", SIGVTALRM},
99 {"STKFLT", SIGSTKFLT},
109 {"VTALRM", SIGVTALRM},
115 {"UNUSED", SIGUNUSED},
120 extern int kill_main (int argc, char **argv)
126 /* Parse any options */
130 while (argc > 0 && **argv == '-') {
136 const struct signal_name *s = signames;
138 while (s->name != 0) {
139 col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
141 fprintf(stderr, "\n");
145 fprintf(stderr, "\n\n");
153 if (isdigit( **argv)) {
155 if (sig < 0 || sig >= NSIG)
164 const struct signal_name *s = signames;
165 while (s->name != 0) {
166 if (strcasecmp (s->name, *argv) == 0) {
189 char pidpath[20]="/proc/";
191 if (! isdigit( **argv)) {
192 fprintf(stderr, "bad PID: %s\n", *argv);
196 snprintf(pidpath, 20, "/proc/%s/stat", *argv);
197 if (stat( pidpath, &statbuf)!=0) {
198 fprintf(stderr, "kill: (%d) - No such pid\n", pid);
201 if (kill (pid, sig) != 0) {
211 fprintf(stderr, "bad signal name: %s\n", *argv);