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.

procpollable.c 633B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <sys/procfs.h>
  5. #include <sys/stropts.h>
  6. #include <poll.h>
  7. int main(int argc, char *argv[])
  8. {
  9. int pid;
  10. char proc[32];
  11. FILE *pfp;
  12. struct pollfd pfd;
  13. pid = fork();
  14. if (pid == 0) {
  15. pause();
  16. exit(0);
  17. }
  18. sprintf(proc, "/proc/%d", pid);
  19. pfp = fopen(proc, "r+");
  20. if (pfp == NULL)
  21. goto fail;
  22. if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
  23. goto fail;
  24. pfd.fd = fileno(pfp);
  25. pfd.events = POLLPRI;
  26. if (poll(&pfd, 1, 0) < 0)
  27. goto fail;
  28. if (!(pfd.revents & POLLPRI))
  29. goto fail;
  30. kill(pid, SIGKILL);
  31. exit(0);
  32. fail:
  33. kill(pid, SIGKILL);
  34. exit(1);
  35. }