SHARE
TWEET

Untitled

a guest Dec 5th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top