]> granicus.if.org Git - strace/blob - test/sfd.c
tests: check decoding of prctl PR_GET_TID_ADDRESS operation
[strace] / test / sfd.c
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 int main(int argc, char *argv[])
7 {
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);
17
18         sfd = open(sname, O_RDONLY);
19         if (sfd == -1) {
20                 perror(sname);
21                 return 1;
22         }
23
24         i = read(sfd, buf, 1024);
25         buf[i] = '\0';
26
27         for (i = 0, s = buf; i < 30; i++) {
28                 while (*++s != ' ') {
29                         if (!*s)
30                                 break;
31                 }
32         }
33
34         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         }
38
39         printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
40
41         return 0;
42 }