1: #ifndef lint
2: static char *sccsid = "@(#)kill.c 4.2 (Berkeley) 10/9/80";
3: #endif
4: /*
5: * kill - send signal to process
6: */
7:
8: #include <whoami.h>
9: #include <signal.h>
10: #include <ctype.h>
11:
12: char *signm[] = { 0,
13: "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "EMT", "FPE", /* 1-8 */
14: "KILL", "BUS", "SEGV", "SYS", "PIPE", "ALRM", "TERM", 0, /* 9-16 */
15: "STOP", "TSTP", "CONT", "CHLD", "TTIN", "TTOU", "TINT", "XCPU", /* 17-24 */
16: "XFSZ", 0, 0, 0, 0, 0, 0, 0, /* 25-31 */
17: };
18:
19: main(argc, argv)
20: char **argv;
21: {
22: register signo, pid, res;
23: int errlev;
24: extern char *sys_errlist[];
25: extern errno;
26:
27: errlev = 0;
28: if (argc <= 1) {
29: usage:
30: printf("usage: kill [ -sig ] pid ...\n");
31: printf("for a list of signals: kill -l\n");
32: exit(2);
33: }
34: if (*argv[1] == '-') {
35: if (argv[1][1] == 'l') {
36: for (signo = 1; signo <= NSIG; signo++) {
37: if (signm[signo])
38: printf("%s ", signm[signo]);
39: if (signo == 16)
40: printf("\n");
41: }
42: printf("\n");
43: exit(0);
44: } else if (isdigit(argv[1][1])) {
45: signo = atoi(argv[1]+1);
46: if (signo < 1 || signo > NSIG) {
47: printf("kill: %s: number out of range\n",
48: argv[1]);
49: exit(1);
50: }
51: } else {
52: char *name = argv[1]+1;
53: for (signo = 1; signo <= NSIG; signo++)
54: if (signm[signo] && !strcmp(signm[signo], name))
55: goto foundsig;
56: printf("kill: %s: unknown signal; kill -l lists signals\n", name);
57: exit(1);
58: foundsig:
59: ;
60: }
61: argc--;
62: argv++;
63: } else
64: signo = SIGTERM;
65: argv++;
66: while (argc > 1) {
67: if (**argv<'0' || **argv>'9')
68: goto usage;
69: res = kill(pid = atoi(*argv), signo);
70: if (res<0) {
71: printf("%u: %s\n", pid, sys_errlist[errno]);
72: errlev = 1;
73: }
74: argc--;
75: argv++;
76: }
77: return(errlev);
78: }
Defined functions
main
defined in line
19;
never used
Defined variables
sccsid
defined in line
2;
never used
signm
defined in line
12; used 4 times