Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 1 | #include "internal.h" |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <signal.h> |
| 6 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 7 | const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n"; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 8 | |
| 9 | struct signal_name { |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 10 | const char *name; |
| 11 | int number; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 12 | }; |
| 13 | |
| 14 | const struct signal_name signames[] = { |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 15 | {"HUP", SIGHUP}, |
| 16 | {"INT", SIGINT}, |
| 17 | {"QUIT", SIGQUIT}, |
| 18 | {"ILL", SIGILL}, |
| 19 | {"TRAP", SIGTRAP}, |
| 20 | {"ABRT", SIGABRT}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 21 | #ifndef __alpha__ |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 22 | {"IOT", SIGIOT}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 23 | #endif |
| 24 | #if defined(sparc) || defined(__alpha__) |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 25 | {"EMT", SIGEMT}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 26 | #else |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 27 | {"BUS", SIGBUS}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 28 | #endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 29 | {"FPE", SIGFPE}, |
| 30 | {"KILL", SIGKILL}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 31 | #if defined(sparc) || defined(__alpha__) |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 32 | {"BUS", SIGBUS}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 33 | #else |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 34 | {"USR1", SIGUSR1}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | #endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 36 | {"SEGV", SIGSEGV}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 37 | #if defined(sparc) || defined(__alpha__) |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 38 | {"SYS", SIGSYS}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 39 | #else |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 40 | {"USR2", SIGUSR2}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 41 | #endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 42 | {"PIPE", SIGPIPE}, |
| 43 | {"ALRM", SIGALRM}, |
| 44 | {"TERM", SIGTERM}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 45 | #if defined(sparc) || defined(__alpha__) |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 46 | {"URG", SIGURG}, |
| 47 | {"STOP", SIGSTOP}, |
| 48 | {"TSTP", SIGTSTP}, |
| 49 | {"CONT", SIGCONT}, |
| 50 | {"CHLD", SIGCHLD}, |
| 51 | {"TTIN", SIGTTIN}, |
| 52 | {"TTOU", SIGTTOU}, |
| 53 | {"IO", SIGIO}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 54 | # ifndef __alpha__ |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 55 | {"POLL", SIGIO}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 56 | # endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 57 | {"XCPU", SIGXCPU}, |
| 58 | {"XFSZ", SIGXFSZ}, |
| 59 | {"VTALRM", SIGVTALRM}, |
| 60 | {"PROF", SIGPROF}, |
| 61 | {"WINCH", SIGWINCH}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 62 | # ifdef __alpha__ |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 63 | {"INFO", SIGINFO}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 64 | # else |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 65 | {"LOST", SIGLOST}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 66 | # endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 67 | {"USR1", SIGUSR1}, |
| 68 | {"USR2", SIGUSR2}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 69 | #else |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 70 | {"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 Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 87 | #endif |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 88 | {0, 0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 91 | extern int kill_main (int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 92 | { |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 93 | int had_error = 0; |
| 94 | int sig = SIGTERM; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 95 | |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 96 | |
| 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 Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 109 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 110 | s++; |
| 111 | if (s->name == 0) |
| 112 | goto end; |
| 113 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame^] | 115 | 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) { |
| 132 | end: |
| 133 | fprintf(stderr, "Usage: %s\n", kill_usage); |
| 134 | exit ( FALSE); |
| 135 | } |
| 136 | exit (TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 137 | } |