Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5.  
  6. int main ()
  7. {
  8.     pid_t pid ;
  9.     printf("Parent process is running and about to fork to a child process\n") ;
  10.    
  11.     pid = fork() ;
  12.    
  13.     if (pid<0)
  14.     {
  15.         fprintf(stderr, "Fork failed") ;
  16.         return 1 ;
  17.     }
  18.     else if (pid==0)
  19.     {
  20.         printf("I am the child process\n") ;
  21.         exit(0) ;
  22.     }
  23.        
  24.     else
  25.     {
  26.         wait(NULL) ;
  27.         printf("Parent acknowledges child termination Parent will terminate now\n") ;
  28.     }
  29.    
  30.     return 0 ;
  31. }
  32.  
  33.  
  34. Output with "gcc Asg3iia.c -o Asg3iia.out && ./Asg3iia.out" :
  35.  
  36. Parent process is running and about to fork to a child process
  37. I am the child process
  38. Parent acknowledges child termination Parent will terminate now
  39.  
  40. Output with "gcc Asg3iia.c -o Asg3iia.out && ./Asg3iia.out | less" :
  41.  
  42. Parent process is running and about to fork to a child process
  43. I am the child process
  44. Parent process is running and about to fork to a child process
  45. Parent acknowledges child termination Parent will terminate now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement