2
0

waitpid.c 395 B

123456789101112131415161718192021
  1. #include <sys/wait.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. pid_t pid = fork();
  7. ERROR_IF(fork, pid, == -1);
  8. if (pid == 0) {
  9. // child
  10. sleep(1);
  11. exit(EXIT_SUCCESS);
  12. } else {
  13. // parent
  14. int stat_loc;
  15. pid_t wid = waitpid(pid, &stat_loc, 0);
  16. ERROR_IF(waitpid, wid, == -1);
  17. }
  18. }