Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3.  // 0 -> 1,2
  4.  // 2-> 3
  5. int main()
  6. {
  7.     int n1 = fork();
  8.     int n2 = fork();
  9.  
  10.     if (n1 > 0 && n2 > 0) {
  11.         printf("parent\n");
  12.         while ((wpid = wait(&status)) > 0);
  13.     }
  14.     else if (n1 == 0 && n2 > 0)
  15.     {
  16.         printf("First child\n");
  17.         exit(0);
  18.     }
  19.     else if (n1 > 0 && n2 == 0)
  20.     {
  21.         printf("Second child\n");  
  22.         exit(0);
  23.     }
  24.     else {
  25.         printf("third child\n");
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement