blob: 00f10f91f364160a8a34bcc71fabb81280d71c95 [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001#include "internal.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <signal.h>
6
Eric Andersen3cf52d11999-10-12 22:26:06 +00007const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n";
Eric Andersencc8ed391999-10-05 16:24:54 +00008
9struct signal_name {
Eric Andersen3cf52d11999-10-12 22:26:06 +000010 const char *name;
11 int number;
Eric Andersencc8ed391999-10-05 16:24:54 +000012};
13
14const struct signal_name signames[] = {
Eric Andersen3cf52d11999-10-12 22:26:06 +000015 {"HUP", SIGHUP},
16 {"INT", SIGINT},
17 {"QUIT", SIGQUIT},
18 {"ILL", SIGILL},
19 {"TRAP", SIGTRAP},
20 {"ABRT", SIGABRT},
Eric Andersencc8ed391999-10-05 16:24:54 +000021#ifndef __alpha__
Eric Andersen3cf52d11999-10-12 22:26:06 +000022 {"IOT", SIGIOT},
Eric Andersencc8ed391999-10-05 16:24:54 +000023#endif
24#if defined(sparc) || defined(__alpha__)
Eric Andersen3cf52d11999-10-12 22:26:06 +000025 {"EMT", SIGEMT},
Eric Andersencc8ed391999-10-05 16:24:54 +000026#else
Eric Andersen3cf52d11999-10-12 22:26:06 +000027 {"BUS", SIGBUS},
Eric Andersencc8ed391999-10-05 16:24:54 +000028#endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000029 {"FPE", SIGFPE},
30 {"KILL", SIGKILL},
Eric Andersencc8ed391999-10-05 16:24:54 +000031#if defined(sparc) || defined(__alpha__)
Eric Andersen3cf52d11999-10-12 22:26:06 +000032 {"BUS", SIGBUS},
Eric Andersencc8ed391999-10-05 16:24:54 +000033#else
Eric Andersen3cf52d11999-10-12 22:26:06 +000034 {"USR1", SIGUSR1},
Eric Andersencc8ed391999-10-05 16:24:54 +000035#endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000036 {"SEGV", SIGSEGV},
Eric Andersencc8ed391999-10-05 16:24:54 +000037#if defined(sparc) || defined(__alpha__)
Eric Andersen3cf52d11999-10-12 22:26:06 +000038 {"SYS", SIGSYS},
Eric Andersencc8ed391999-10-05 16:24:54 +000039#else
Eric Andersen3cf52d11999-10-12 22:26:06 +000040 {"USR2", SIGUSR2},
Eric Andersencc8ed391999-10-05 16:24:54 +000041#endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000042 {"PIPE", SIGPIPE},
43 {"ALRM", SIGALRM},
44 {"TERM", SIGTERM},
Eric Andersencc8ed391999-10-05 16:24:54 +000045#if defined(sparc) || defined(__alpha__)
Eric Andersen3cf52d11999-10-12 22:26:06 +000046 {"URG", SIGURG},
47 {"STOP", SIGSTOP},
48 {"TSTP", SIGTSTP},
49 {"CONT", SIGCONT},
50 {"CHLD", SIGCHLD},
51 {"TTIN", SIGTTIN},
52 {"TTOU", SIGTTOU},
53 {"IO", SIGIO},
Eric Andersencc8ed391999-10-05 16:24:54 +000054# ifndef __alpha__
Eric Andersen3cf52d11999-10-12 22:26:06 +000055 {"POLL", SIGIO},
Eric Andersencc8ed391999-10-05 16:24:54 +000056# endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000057 {"XCPU", SIGXCPU},
58 {"XFSZ", SIGXFSZ},
59 {"VTALRM", SIGVTALRM},
60 {"PROF", SIGPROF},
61 {"WINCH", SIGWINCH},
Eric Andersencc8ed391999-10-05 16:24:54 +000062# ifdef __alpha__
Eric Andersen3cf52d11999-10-12 22:26:06 +000063 {"INFO", SIGINFO},
Eric Andersencc8ed391999-10-05 16:24:54 +000064# else
Eric Andersen3cf52d11999-10-12 22:26:06 +000065 {"LOST", SIGLOST},
Eric Andersencc8ed391999-10-05 16:24:54 +000066# endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000067 {"USR1", SIGUSR1},
68 {"USR2", SIGUSR2},
Eric Andersencc8ed391999-10-05 16:24:54 +000069#else
Eric Andersen3cf52d11999-10-12 22:26:06 +000070 {"STKFLT", SIGSTKFLT},
71 {"CHLD", SIGCHLD},
72 {"CONT", SIGCONT},
73 {"STOP", SIGSTOP},
74 {"TSTP", SIGTSTP},
75 {"TTIN", SIGTTIN},
76 {"TTOU", SIGTTOU},
77 {"URG", SIGURG},
78 {"XCPU", SIGXCPU},
79 {"XFSZ", SIGXFSZ},
80 {"VTALRM", SIGVTALRM},
81 {"PROF", SIGPROF},
82 {"WINCH", SIGWINCH},
83 {"IO", SIGIO},
84 {"POLL", SIGPOLL},
85 {"PWR", SIGPWR},
86 {"UNUSED", SIGUNUSED},
Eric Andersencc8ed391999-10-05 16:24:54 +000087#endif
Eric Andersen3cf52d11999-10-12 22:26:06 +000088 {0, 0}
Eric Andersencc8ed391999-10-05 16:24:54 +000089};
90
Eric Andersen3cf52d11999-10-12 22:26:06 +000091extern int kill_main (int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000092{
Eric Andersen3cf52d11999-10-12 22:26:06 +000093 int had_error = 0;
94 int sig = SIGTERM;
Eric Andersencc8ed391999-10-05 16:24:54 +000095
Eric Andersen3cf52d11999-10-12 22:26:06 +000096
97
98 if (argv[1][0] == '-') {
99 if (argv[1][1] >= '0' && argv[1][1] <= '9') {
100 sig = atoi (&argv[1][1]);
101 if (sig < 0 || sig >= NSIG)
102 goto end;
103 } else {
104 const struct signal_name *s = signames;
105 for (;;) {
106 if (strcmp (s->name, &argv[1][1]) == 0) {
107 sig = s->number;
108 break;
Eric Andersencc8ed391999-10-05 16:24:54 +0000109 }
Eric Andersen3cf52d11999-10-12 22:26:06 +0000110 s++;
111 if (s->name == 0)
112 goto end;
113 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000114 }
Eric Andersen3cf52d11999-10-12 22:26:06 +0000115 argv++;
116 argc--;
117
118 }
119 while (argc > 1) {
120 int pid;
121 if (argv[1][0] < '0' || argv[1][0] > '9')
122 goto end;
123 pid = atoi (argv[1]);
124 if (kill (pid, sig) != 0) {
125 had_error = 1;
126 perror (argv[1]);
127 }
128 argv++;
129 argc--;
130 }
131 if (had_error) {
132end:
Eric Andersenb0e9a701999-10-18 22:28:26 +0000133 usage (kill_usage);
Eric Andersen3cf52d11999-10-12 22:26:06 +0000134 }
135 exit (TRUE);
Eric Andersencc8ed391999-10-05 16:24:54 +0000136}