Question: Problem 2 Write a C program on Linux that creates children processes and does the following: Part I: - The parent process creates 1 child.

Problem 2

Write a C program on Linux that creates children processes and does the following:

Problem 2 Write a C program on Linux that creates children processes

Part I: - The parent process creates 1 child. - The child process itself creates 1 child. This will be the grandchild of the parent. - The parent process reads one number (integer) from the standard input. The parent process sends this number to the child using standard pipes. - The child multiplies the number by 2, prints it as "Child: Input X, Output X*2" and sends the result to the grandchild. - The grandchild multiplies the input number by 2, prints it as "Grandchild: Input X, Output X*2" and sends it back to the child. - The child will send the result back to the parent. - The parent prints the final result. - The parent kills all children processes, and terminates. Part II: Add a sleep(5) parameter to each process operation, so that you can track the behavior as it executes. Open two terminals. In the first terminal, run the tool *htop*. Once in htop, press *t* to sort all processes as a process tree. Resize the window so that you can see the processes properly. In the second terminal, execute your program. Find the program in htop, and take a screenshot of its hierarchy (parent/child/grandchild). Kill the child process amidst execution by pressing *k* in htop, and sending it SIGKILL to immediately terminate it. Take a screenshot of the program execution output. For Problem 2, you may need to use sleep(), kill() and fork() system calls. Refer to the ordinary pipe example in the textbook

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!