summaryrefslogtreecommitdiff
path: root/test/sfd.c
blob: 815da80bdd0019fe6f9a5b5694dc360b1b016883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
	int pid = atoi(argv[1]);
	int sfd;
	char sname[32];
	char buf[1024];
	char *s;
	int i;
	int signal, blocked, ignore, caught;

	sprintf(sname, "/proc/%d/stat", pid);

	sfd = open(sname, O_RDONLY);
	if (sfd == -1) {
		perror(sname);
		return 1;
	}

	i = read(sfd, buf, 1024);
	buf[i] = '\0';

	for (i = 0, s = buf; i < 30; i++) {
		while (*++s != ' ') {
			if (!*s)
				break;
		}
	}

	if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
		fprintf(stderr, "/proc/pid/stat format error\n");
		return 1;
	}

	printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);

	return 0;
}