SYSENTER/SYSCALL support
[minix.git] / commands / kill / kill.c
blobbb957960ce12b3350b1ef022f3998c589f5bf924
1 /* kill - send a signal to a process Author: Adri Koppes */
3 #include <sys/types.h>
4 #include <errno.h>
5 #include <signal.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdio.h>
10 int main(int argc, char **argv);
11 void usage(void);
13 /* Table of signal names. */
14 struct signames {
15 char *name;
16 int sig;
17 } signames[] = {
18 { "HUP", SIGHUP },
19 { "INT", SIGINT },
20 { "QUIT", SIGQUIT },
21 { "ILL", SIGILL },
22 { "TRAP", SIGTRAP },
23 { "ABRT", SIGABRT },
24 { "IOT", SIGIOT },
25 { "FPE", SIGFPE },
26 { "KILL", SIGKILL },
27 { "USR1", SIGUSR1 },
28 { "SEGV", SIGSEGV },
29 { "USR2", SIGUSR2 },
30 { "PIPE", SIGPIPE },
31 { "ALRM", SIGALRM },
32 { "TERM", SIGTERM },
33 { "EMT", SIGEMT },
34 { "BUS", SIGBUS },
35 { "CHLD", SIGCHLD },
36 { "CONT", SIGCONT },
37 { "STOP", SIGSTOP },
38 { "TSTP", SIGTSTP },
39 { "TTIN", SIGTTIN },
40 { "TTOU", SIGTTOU },
41 #ifdef SIGWINCH
42 { "WINCH", SIGWINCH },
43 #endif
44 { "VTALRM", SIGVTALRM },
45 { "PROF", SIGPROF },
46 { NULL, 0 }
49 int main(argc, argv)
50 int argc;
51 char **argv;
53 pid_t proc;
54 int ex = 0, sig = SIGTERM;
55 char *end;
56 long l;
57 unsigned long ul;
58 struct sigaction sa;
59 int i, doit;
60 struct signames *snp;
62 if (argc > 1 && argv[1][0] == '-') {
63 sig = -1;
64 for (snp = signames; snp->name != NULL; snp++) { /* symbolic? */
65 if (strcmp(snp->name, argv[1] + 1) == 0) {
66 sig = snp->sig;
67 break;
70 if (sig < 0) { /* numeric? */
71 ul = strtoul(argv[1] + 1, &end, 10);
72 if (end == argv[1] + 1 || *end != 0 || ul >= _NSIG) usage();
73 sig = ul;
75 argv++;
76 argc--;
78 sa.sa_flags = 0;
79 sigemptyset(&sa.sa_mask);
80 sa.sa_handler = SIG_IGN; /* try not to kill yourself */
81 (void) sigaction(sig, &sa, (struct sigaction *) NULL);
83 for (doit = 0; doit <= 1; doit++) {
84 for (i = 1; i < argc; i++) {
85 l = strtoul(argv[i], &end, 10);
86 if (end == argv[i] || *end != 0 || (pid_t) l != l) usage();
87 proc = l;
88 if (doit && kill(proc, sig) < 0) {
89 fprintf(stderr, "kill: %d: %s\n",
90 proc, strerror(errno));
91 ex = 1;
95 return(ex);
98 void usage()
100 fprintf(stderr, "Usage: kill [-sig] pid\n");
101 exit(1);