summaryrefslogtreecommitdiff
path: root/test/sfd.c
blob: 081de01e20d8e804765edf0091686d270bcc18e3 (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
#include <fcntl.h>
#include <stdio.h>
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);
	if ((sfd = open(sname, O_RDONLY)) == -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 1;
}