Question: 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

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 childs PID to the parent process and zero to the child process. (You dont have to type the comments.)

#include 
#include 
main ( ) 
{
 int result ;
 
 printf("%d: I am the parent. Remember my number! ", getpid( ) ); 
 printf("%d: I am now going to fork ... ", getpid( ) ); 
 
 result = fork ( ) ; 
 
 if (result != 0) 
 { /* the parent will execute this code */ 
 printf("%d: My child's pid is %d ", getpid ( ), result ); 
 } 
 else /* result == 0 */
 { /* the child will execute this code */ 
 printf("%d: Hi ! I am the child. ", getpid ( ) ) ; 
 exit (1) ; 
 } 
 
 printf("%d: like father like son. ", getpid ( ) );
}

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

Use this online terminal CoCalc to answer the question.

Solve this in 30 minutes and you will be granted an upvote. That's a promise.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!