Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | #include <fcntl.h> |
| 2 | #include <stdio.h> |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 3 | |
| 4 | int main(int argc, char *argv[]) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 5 | { |
| 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 Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 15 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 16 | if ((sfd = open(sname, O_RDONLY)) == -1) { |
| 17 | perror(sname); |
| 18 | return 1; |
| 19 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 20 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 21 | i = read(sfd, buf, 1024); |
| 22 | buf[i] = '\0'; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 23 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 24 | for (i = 0, s = buf; i < 30; i++) { |
| 25 | while (*++s != ' ') { |
| 26 | if (!*s) |
| 27 | break; |
| 28 | } |
| 29 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 30 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 31 | if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) { |
| 32 | fprintf(stderr, "/proc/pid/stat format error\n"); |
| 33 | return 1; |
| 34 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 35 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught); |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 37 | |
| 38 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 39 | } |