Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 modulus
the final output should look something like:
pipeline completed with initial value
pipeline completed with initial value
assembly line produced working units
assembly line produced fixable units
The number is the sum of the numbers in the array, and thus results in at the end. Working units reflect the Consumer count. Fixable units reflect the Consumer positive count.
I gave you the template code screenshot and the above instructions also. I tried it in GPT But didn't get the output as per the requirement. Im getting errors while executing the chatgpt code. I need the code in C language and I use Cstar complier. Please use template format and dont add any extra #include or #define functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started