waitpid.c 383 B

1234567891011121314151617
  1. #include <sys/wait.h>
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. int main()
  6. {
  7. int status;
  8. pid_t p = getpid();
  9. // waitpid takes a children's pid, not the current process one
  10. // if the pid is not a children of the current process, it returns -ECHILD
  11. pid_t res = waitpid(1001, &status, WNOHANG);
  12. printf("res is %d, p is %d and errno is %d\n", res, p, errno);
  13. }