source: trunk/minix/commands/simple/kill.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 2.0 KB
Line 
1/* kill - send a signal to a process Author: Adri Koppes */
2
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>
9
10_PROTOTYPE(int main, (int argc, char **argv));
11_PROTOTYPE(void usage, (void));
12
13/* Table of signal names. */
14struct 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 { NULL, 0 }
45};
46
47int main(argc, argv)
48int argc;
49char **argv;
50{
51 pid_t proc;
52 int ex = 0, sig = SIGTERM;
53 char *end;
54 long l;
55 unsigned long ul;
56 struct sigaction sa;
57 int i, doit;
58 struct signames *snp;
59
60 if (argc > 1 && argv[1][0] == '-') {
61 sig = -1;
62 for (snp = signames; snp->name != NULL; snp++) { /* symbolic? */
63 if (strcmp(snp->name, argv[1] + 1) == 0) {
64 sig = snp->sig;
65 break;
66 }
67 }
68 if (sig < 0) { /* numeric? */
69 ul = strtoul(argv[1] + 1, &end, 10);
70 if (end == argv[1] + 1 || *end != 0 || ul > _NSIG) usage();
71 sig = ul;
72 }
73 argv++;
74 argc--;
75 }
76 sa.sa_flags = 0;
77 sigemptyset(&sa.sa_mask);
78 sa.sa_handler = SIG_IGN; /* try not to kill yourself */
79 (void) sigaction(sig, &sa, (struct sigaction *) NULL);
80
81 for (doit = 0; doit <= 1; doit++) {
82 for (i = 1; i < argc; i++) {
83 l = strtoul(argv[i], &end, 10);
84 if (end == argv[i] || *end != 0 || (pid_t) l != l) usage();
85 proc = l;
86 if (doit && kill(proc, sig) < 0) {
87 fprintf(stderr, "kill: %d: %s\n",
88 proc, strerror(errno));
89 ex = 1;
90 }
91 }
92 }
93 return(ex);
94}
95
96void usage()
97{
98 fprintf(stderr, "Usage: kill [-sig] pid\n");
99 exit(1);
100}
Note: See TracBrowser for help on using the repository browser.