strace/test/sfd.c
Denys Vlasenko 5d64581e10 Improve code readability by avoiding assignments inside if()
* desc.c (decode_select): Move assignment out of if() condition.
* file.c (sprinttime): Likewise.
(sys_getdirentries): Likewise.
* io.c (sys_ioctl): Likewise.
* strace.c (test_ptrace_setoptions_followfork): Likewise.
(main): Likewise.
(proc_open): Likewise.
(detach): Likewise.
(proc_poll): Likewise.
(trace): Likewise.
* syscall.c (qualify): Likewise.
(sys_indir): Likewise.
* test/procpollable.c (main): Likewise.
* test/sfd.c (main): Likewise.
* time.c (printtv_bitness): Likewise.
(sprinttv): Likewise.
(print_timespec): Likewise.
(void sprint_timespec): Likewise.
(printitv_bitness): Likewise.
* util.c (dumpstr): Likewise.
(umovestr): Likewise.
(fixvfork): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:01 +02:00

41 lines
675 B
C

#include <fcntl.h>
#include <stdio.h>
int 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);
sfd = open(sname, O_RDONLY);
if (sfd == -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 0;
}