Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_posix/sys/src/ape/cmd/kill.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <stdlib.h>
2
#include <sys/types.h>
3
#include <unistd.h>
4
#include <signal.h>
5
#include <ctype.h>
6
#include <stdio.h>
7
#include <string.h>
8
 
9
#define NSIG SIGUSR2
10
 
11
char *signm[NSIG+1] = { 0,
12
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGABRT", "SIGFPE", "SIGKILL", /* 1-7 */
13
"SIGSEGV", "SIGPIPE", "SIGALRM", "SIGTERM", "SIGUR1", "SIGUSR2", /* 8-13 */
14
};
15
 
16
main(int argc, char **argv)
17
{
18
	int signo, pid, res;
19
	int errlev;
20
 
21
	errlev = 0;
22
	if (argc <= 1) {
23
	usage:
24
		fprintf(stderr, "usage: kill [ -sig ] pid ...\n");
25
		fprintf(stderr, "for a list of signals: kill -l\n");
26
		exit(2);
27
	}
28
	if (*argv[1] == '-') {
29
		if (argv[1][1] == 'l') {
30
			int i = 0;
31
			for (signo = 1; signo <= NSIG; signo++)
32
				if (signm[signo]) {
33
					printf("%s ", signm[signo]);
34
					if (++i%8 == 0)
35
						printf("\n");
36
				}
37
			if(i%8 !=0)
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
				fprintf(stderr, "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 = 1; signo <= NSIG; signo++)
50
				if (signm[signo] && (
51
				    !strcmp(signm[signo], name)||
52
				    !strcmp(signm[signo]+3, name)))
53
					goto foundsig;
54
			fprintf(stderr, "kill: %s: unknown signal; kill -l lists signals\n", name);
55
			exit(1);
56
foundsig:
57
			;
58
		}
59
		argc--;
60
		argv++;
61
	} else
62
		signo = SIGTERM;
63
	argv++;
64
	while (argc > 1) {
65
		if ((**argv<'0' || **argv>'9') && **argv!='-')
66
			goto usage;
67
		res = kill(pid = atoi(*argv), signo);
68
		if (res<0) {
69
			perror("kill");
70
		}
71
		argc--;
72
		argv++;
73
	}
74
	return(errlev);
75
}