Question: In this assignment, create a pipeline of processes that each apply a unique tool to the work that is given to them before passing it

In this assignment, create a pipeline of processes that each apply a unique tool to the work that is given to them before passing it on to the next process.
Producer process specification: (about 12 lines of code)
Generate a sequence of 32000 random numbers from 1<= r <=32765(use the stdlib.h rand() function, and take the random number mod 32765) and send each to the first Worker process in the pipeline in a message of the form
typedef struct {
int initial;
int current;
} message;
setting both fields to the random value. For termination, set both fields to 0, and send the final message.
Consumer process specification: (about 26 lines of code)
1. Receive the next message and apply the process tool to the message. Count the number of zero and positive results separately
2. End when a 0 message is received, and display the 0 and positive counts
Worker process specification: (about 17 lines of code)
1. Receive the next message and apply the process tool to the message current field. If the result is positive, update the message current field with the result and send the message to the next process
2. End when a 0 message is received
The tools for each process to apply to the message are the 100 unique numbers provided in the template code. "Apply the tool" means subtract it from the current value.
The main process (about 13 lines of code) should start the Producer process, the 99 Worker processes, and the Consumer process (the 100th worker). Each process receives as parameters its unique tool and the one or two channels (streams) it needs to operate. Since the main process starts 101 processes, it can execute 101 joins to wait for the pipeline to end.
Hints:
1. use the template code, and start the processes using FORK
2. use an array of 100 channels (message streams)
3. remember that each channel has a send and receive side, so each channel is passed to two adjacent Worker processes, excepting the Producer and Consumer that need only one channel
4. start with a small set of processes, such as 5 processes and the first four numbers (also use a smaller modu

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!