Question: a) Write a C program to Implement a system of three processes which read and write numbers to a file. Each of the three

a) Write a C program to Implement a system of three processes which read and write numbers to a file. Each of

a) Write a C program to Implement a system of three processes which read and write numbers to a file. Each of the three processes P1, P2, and P3 must obtain an integer from the file (these instructions must be executed 200 times). The file only holds one integer at any given time. Given a file F, containing a single integer N, each process must perform the following steps (25 points): 1. Fork two processes For 200 times: 2. 3. 4. 5. 6. 6819 7. 8. 9. Open F Read the integer N from the file Close F Output N and the process' PID (On the screen) Increment N by 1 Open F Write N to F (overwriting the current value in F) Close F b) Briefly describe why the processes P1, P2, and P3 obtain/read duplicates of numbers (why does a particular integer x appear in the output of more than one process)? (3 points) c) Suggest a solution (you do not need to implement it) to guarantee that no duplicate numbers are ever obtained by the processes. In other words, each time the file is read by any process, that process reads a distinct integer. (2 points)

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Heres a simplified C program that implements the described system with three processes P1 P2 and P... View full answer

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 Computer Network Questions!