Answered step by step
Verified Expert Solution
Link Copied!

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 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 modulus)
5. the final output should look something like:
pipeline completed with initial value 24678
pipeline completed with initial value 24678
assembly line produced 2 working units
assembly line produced 7849 fixable units
The number 24678 is the sum of the 100 numbers in the array, and thus results in 0 at the end. Working units reflect the Consumer 0 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 4. But didn't get the output as per the requirement. I'm getting errors while executing the chat-gpt 4 code. I need the code in C language and I use C*star complier. Please use template format and dont add any extra #include or #define functions.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

ISBN: 1680838482, 978-1680838480

More Books

Students also viewed these Databases questions

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago