Question: A. In this part , you are asked to write a Python program using the fork() system call to create a child process to sort

A. In this part, you are asked to write a Python program using the fork() system call to create a child process to sort an array of randomly generated integers (with values between 0 and 99). The array size should be entered from the command line so that it can be changed from run to run (limit your array size to 20.) The parent process is responsible for generating this array of integers and the child process responsible for sorting the elements stored in this array in non-decreasing order. Have the parent invoke the wait() system call to wait for the child process to complete before exiting the program. Your output should consist of the original unsorted array printed from the parent and the sorted array printed directly from the child. For readability reasons, you should clearly indicate theprocess that produces the output. DO NOT just printout the numbers. Your program should also perform necessary error checking for graceful termination if something goes wrong.

B. Without resorting to some inter-process communication means, the parent process in Part A has to rely on the child process to print out the results of the sorted array. In this part, therefore, you are asked to extend the program you wrote in part A to include a pipe() system call so that the parent process doesnt have to rely on the child process for printingthe sorted array. What the child process needs to doin this case is to write the contents of the sorted arrayto an ordinary pipe for the parent to read. Note that your output of the sorted array should be performed by the parent process.

C. After having received the sorted array from the child, the parent should print out the elements in the array in reverse order and send an acknowledgement message back to the child, indicating that the sorted array has been successfully received. The child process then print out the message received from the parent and exit.

D. Incorporate all the source code you have completed into a single program; compile it; and run it. It is recommended that you test your program step by step by gradually incorporating different parts into the program, starting from Part A, then B, and finally C.

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!