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 lines of code
Generate a sequence of random numbers from r use the stdlib.h rand function, and take the random number mod 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 and send the final message.
Consumer process specification: about lines of code
Receive the next message and apply the process tool to the message. Count the number of zero and positive results separately
End when a message is received, and display the and positive counts
Worker process specification: about lines of code
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
End when a message is received
The tools for each process to apply to the message are the unique numbers provided in the template code. "Apply the tool" means subtract it from the current value.
The main process about lines of code should start the Producer process, the Worker processes, and the Consumer process the th 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 processes, it can execute joins to wait for the pipeline to end.
Hints:
use the template code, and start the processes using FORK
use an array of channels message streams
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
start with a small set of processes, such as 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
