Question: Lloyd 3302 -You will need to write a single file of source code in C++. 1. You will need to have a Command line argument

Lloyd 3302

-You will need to write a single file of source code in C++.

1. You will need to have a Command line argument that tells the program how many children processes it needs to spawn.

Please note the format for this argument should be like this: -p . Example: ./forkexample p 7. This will have the program create 7 children processes giving us 8 total.

-You will need to keep track of the PIDs of all the children. As such you will need to create an array to store these values inside.

Two functions to be run. A parent function and a child function. These functions are to be run based on which process is the one calling it.

The child function should create a new counting loop (much like the example in class) and count 10 times. It should print out the PID of the child as well as the current value of the counter.

The parent function needs to perform 2 different tasks.

It needs to wait until all of the children processes are complete

Once all children process are complete, it should display a message showing all of the child processes then a message saying that the program has completed.

The parent process ONLY should create the number of children specified by the command line. DO NOT let the children spawn processes (this will result in unwanted processes being created).

You need to call the appropriate function based on which process is running after all fork calls have been currently made.

Let me know if you have any questions!

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!