Advertisement
deadlykingdx

*NEW* OS 2 C

Jan 10th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5. #include <time.h>
  6.  
  7. int print_my_info(int pid){
  8.     printf("I am process: %d and my parent is: %d and my child is: %d\n", getpid(),getppid(),pid);
  9.     return 1;
  10. }
  11. int main()
  12. {
  13.     int pid;
  14.     int z=0;
  15.     for(int i=1;i<=5;i++)
  16.     {
  17.         z++;
  18.         if((pid=fork())>0)
  19.         {
  20.             print_my_info(pid);
  21.             wait(NULL);
  22.             exit(0);
  23.  
  24.         }
  25.         if (z==5){
  26.             print_my_info(pid);
  27.         }
  28.     }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement