Advertisement
deadlykingdx

Operating Systems 2 1.C

Jan 9th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  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.  
  12. int main(){
  13.     int pid=fork();
  14.     if(pid>0){
  15.         printf("0:");
  16.         print_my_info(pid);
  17.     }
  18.     else{
  19.         pid=fork();
  20.         if(pid>0){
  21.             printf("1:");
  22.             print_my_info(pid);
  23.         }
  24.         else{
  25.             pid=fork();
  26.             if (pid>0){
  27.                 printf("2:");
  28.                 print_my_info(pid);
  29.             }
  30.             else{
  31.                 pid=fork();
  32.                 if(pid>0){
  33.                     printf("3:");
  34.                     print_my_info(pid);
  35.                 }
  36.                 else{
  37.                     pid=fork();
  38.                 if(pid>0){
  39.                     printf("4:");
  40.                     print_my_info(pid);
  41.                 }
  42.                 else{
  43.                     printf("5:");
  44.                     print_my_info(pid);
  45.                 }
  46.                 }
  47.  
  48.             }
  49.         }
  50.     }
  51.     wait(NULL);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement