Question: Write a program named , which should take one command-line argument called maxnum. prseq should fork two child processes. Together, these three processes will print

Write a program named , which should take one command-line argument called maxnum. prseq should fork two child processes. Together, these three processes will print the sequence of integers from 0 up to maxnum (inclusive), one on each line. Your code must satisfy the following requirements:

The parent process will print out 0, 3, 6, 9, etc.

One of the two child processes will print out 1, 4, 7, etc.

The other child process will print out 2, 5, 8, etc.

The output should be in strictly increasing order, i.e., 0, 1, 2, 3, 4, 5, 6, 7, 8, , up to maxnum (inclusive), one number per line (you may want to include other hints, such as which process is printing the number, parent, child1, or child2).

*Semaphores must be used to synchronize the processes. Any other methods will be treated as wrong answers. Therefore, if your code doesnt use any semaphores, its wrong.

Compile and run your code with different inputs to show that your code works as required. Take the snapshots and insert them into your Word document for submission.

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!