Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program A code: //Note: pipes are not bi-directional, so you will need two pipes per process, one for receiving (reading) and one for sending (writing).

image text in transcribed

Program A code:

//Note: pipes are not bi-directional, so you will need two pipes per process, one for receiving (reading) and one for sending (writing). if you the to send (write) something using pipe1 you need to close the reading end of that pipe, namely close(pipe1[0]). In the same way, if you need to receive something from the someone, you have to use another pipe, let say pipe2, so you use the reading end part and close the writing end, namely close(pipe2[1]) */ //Sorry for any typo, I hope that this code will help you to beeter understand, how to use the API for process. Feel free to extend this code for two and three childrens. #include #include #include #include int main(int argv, char** argc) { // initialize pipes int p1[2]; int p2[2]; pipe(p1); pipe(p2); int luis; int numElements = 6; /um of elements in the array luis = fork(); //creating a child if (luis == 0) { // If I am the child read the elements of the array that my parent sent me close(p1[1]); //closing the writing end of pipe1 (p1), I am using p1 for reading so p1[0] is open for reading from my parent close(p2[0]); //closing the reading end of pipe2 (p2), I am using p2 for sending (writing) the sumation to my parent int vals[numElements]; read(p1[0], &vals, sizeof(vals)); // compute the sum int sum = 0; printf("child %d: received ", getpid()); //printing my pid and the array that I just received from my parent int i; for (i=0;i ProgramB Here, you can recycle most of the code from ProgramA. The only difference is that now the parent program will create a variable number of children (for this problem 2 or 3) instead of just one child, and it will send a piece of the array to each child. Each child will compute the summation of its array and it will print it along with its process ID Then, each child will send the summation to its parent. The parent will collect the partial

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 Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

Why are more ventures started by teams than by solo entrepreneurs?

Answered: 1 week ago

Question

5. What is the purpose of the coefficient of variation?

Answered: 1 week ago