Question: EXCERSICES 1. Use the template below to write a C-program that creates two processes: Process A (the process with which the program starts execution) and

 EXCERSICES 1. Use the template below to write a C-program that

EXCERSICES 1. Use the template below to write a C-program that creates two processes: "Process A" (the process with which the program starts execution) and "Process B" (A's child). The Process A forks Process B. To identify which process writes the output, each process puts its id at the beginning of each line (see the sample output). Each process performs the following operations Process A: After spawning Process B, it waits for Process B to terminate. After Process B's termination, it will write your home directory (use HOME environment variable) and its process ID, and terminates. Process B: After being spawned from Process A, it sleeps for three seconds (using sleep) Then, it writes process IDs of itself and Process A immediately. After that, executes ps command (using system library) and terminates. Sample output: ./a.out 9181:1 am the parent, I will create child process 9182:1 am the child, I will sleep for 3 seconds 9182:My parent pid is 9181 9182:the ps command PID TTY TIME CMD 8931 pts/0 00:00:00 bash 9181 pts/0 00:00:00 a.out 9182 pts/0 00:00:00 a.out 9183 pts/0 00:00:00 ps 9181: My home directory is /home/user Template: 78 Page #include #include /* contains fork prototype */ main(void) int pid,status; 1/printf the first message //fork B process if (pid == 0) 1/child process C // print message // sleep 3 seconds // print message // print message // executes ps command printf(" "); ) else // parent waits for child to finish // print message system("echo SHOME"); printf(" ")

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!