Use pico to type and save the following program as labrep.c . Compile and run the program to observe that fork() returns the value of the child’s PID to the parent process and zero to the child...



  1. Usepico to type and save the following program aslabrep.c. Compile and run the program to observe thatfork() returns the value of the child’s PID to the parent process and zero to the child process. (You don’t have to type the comments.)



#include



#include



main ( )



{



 int  result ;





 printf("%d:  I am the parent. Remember my number!\n", getpid( ) );



 printf("%d:  I am now going to fork ... \n", getpid( ) );




   result = fork ( ) ;





   if (result != 0)



   {    /* the parent will execute this code */



     printf("%d:  My child's pid is %d\n", getpid ( ), result );



   }



   else     /* result == 0 */



   {        /* the child will execute this code */



      printf("%d:  Hi !  I am the child.\n", getpid ( ) ) ;



      exit (1) ;



   }





      printf("%d:  like father like son. \n", getpid ( ) );



}


Write the output of the program. Draw a process three and label the processes with their process IDs.




















Output
















Process Tree











Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here