blob: 815da80bdd0019fe6f9a5b5694dc360b1b016883 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001#include <fcntl.h>
2#include <stdio.h>
Denys Vlasenko8ed57272009-02-25 14:24:02 +00003
4int main(int argc, char *argv[])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00005{
6 int pid = atoi(argv[1]);
7 int sfd;
8 char sname[32];
9 char buf[1024];
10 char *s;
11 int i;
12 int signal, blocked, ignore, caught;
13
14 sprintf(sname, "/proc/%d/stat", pid);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000015
Denys Vlasenko5d645812011-08-20 12:48:18 +020016 sfd = open(sname, O_RDONLY);
17 if (sfd == -1) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000018 perror(sname);
19 return 1;
20 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000021
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000022 i = read(sfd, buf, 1024);
23 buf[i] = '\0';
Denys Vlasenko8ed57272009-02-25 14:24:02 +000024
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000025 for (i = 0, s = buf; i < 30; i++) {
26 while (*++s != ' ') {
27 if (!*s)
28 break;
29 }
30 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000031
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032 if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
33 fprintf(stderr, "/proc/pid/stat format error\n");
34 return 1;
35 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000036
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037 printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000038
39 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040}