blob: 34eec7dc1d281ff569a138c018db7c745d1ba63f [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001#include <fcntl.h>
2#include <stdio.h>
Elliott Hughes5061ef22015-02-19 21:27:55 -08003#include <stdlib.h>
4#include <unistd.h>
Denys Vlasenko8ed57272009-02-25 14:24:02 +00005
6int main(int argc, char *argv[])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007{
8 int pid = atoi(argv[1]);
9 int sfd;
10 char sname[32];
11 char buf[1024];
12 char *s;
13 int i;
14 int signal, blocked, ignore, caught;
15
16 sprintf(sname, "/proc/%d/stat", pid);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000017
Denys Vlasenko5d645812011-08-20 12:48:18 +020018 sfd = open(sname, O_RDONLY);
19 if (sfd == -1) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000020 perror(sname);
21 return 1;
22 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000023
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000024 i = read(sfd, buf, 1024);
25 buf[i] = '\0';
Denys Vlasenko8ed57272009-02-25 14:24:02 +000026
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000027 for (i = 0, s = buf; i < 30; i++) {
28 while (*++s != ' ') {
29 if (!*s)
30 break;
31 }
32 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000033
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034 if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
35 fprintf(stderr, "/proc/pid/stat format error\n");
36 return 1;
37 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000038
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039 printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000040
41 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042}