Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/wait.h>
  5.  
  6. int main(void)
  7. {
  8. pid_t child_pid, wpid;
  9. int status = 0;
  10. int i;
  11. int a[3] = {1, 2, 1};
  12.  
  13. printf("parent_pid = %d\n", getpid());
  14. for (i = 0; i < 3; i++)
  15. {
  16. printf("i = %d\n", i);
  17. if ((child_pid = fork()) == 0)
  18. {
  19. printf("In child process (pid = %d)\n", getpid());
  20. if (a[i] < 2)
  21. {
  22. printf("Should be accept\n");
  23. exit(1);
  24. }
  25. else
  26. {
  27. printf("Should be reject\n");
  28. exit(0);
  29. }
  30. /*NOTREACHED*/
  31. }
  32. }
  33.  
  34. while ((wpid = wait(&status)) > 0)
  35. {
  36. printf("Exit status of %d was %d (%s)\n", (int)wpid, status,
  37. (status > 0) ? "accept" : "reject");
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement