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