Advertisement
Guest User

friday

a guest
Jul 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. #define COUNT 4
  5.  
  6. int main(void) {
  7.  
  8.  
  9. int count = COUNT, children = 0;
  10.  
  11.  
  12. pid_t retpid = 1;
  13.  
  14.  
  15.  
  16. while (count-- > 0 && retpid > 0)
  17.  
  18.  
  19. if ((retpid = fork()) > 0)
  20. children++;
  21.  
  22.  
  23.  
  24. if (retpid != 0) {
  25. printf("Parent PID %d\n", getpid());
  26.  
  27.  
  28.  
  29. while (children-- > 0)
  30. wait(NULL);
  31. } else {
  32.  
  33.  
  34. printf("Child PID %d, PPID %d\n", getpid(), getppid());
  35. }
  36.  
  37. sleep(90);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement