Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sfd.c 715B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. int main(int argc, char *argv[])
  6. {
  7. int pid = atoi(argv[1]);
  8. int sfd;
  9. char sname[32];
  10. char buf[1024];
  11. char *s;
  12. int i;
  13. int signal, blocked, ignore, caught;
  14. sprintf(sname, "/proc/%d/stat", pid);
  15. sfd = open(sname, O_RDONLY);
  16. if (sfd == -1) {
  17. perror(sname);
  18. return 1;
  19. }
  20. i = read(sfd, buf, 1024);
  21. buf[i] = '\0';
  22. for (i = 0, s = buf; i < 30; i++) {
  23. while (*++s != ' ') {
  24. if (!*s)
  25. break;
  26. }
  27. }
  28. if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
  29. fprintf(stderr, "/proc/pid/stat format error\n");
  30. return 1;
  31. }
  32. printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
  33. return 0;
  34. }