Question
This program should use the fork() instruction to create 1, 2, or 3 children. If the parent creates just a child, the parent will send
This program should use the fork() instruction to create 1, 2, or 3 children. If the parent creates just a child, the parent will send the array to the child. The child will receive the array and it will add its elements. Then the child will send the summation to the parent who will print that summation. Now if the parent creates two children, it will send the first half of the array to one child and the second half to another one. Each child will receive the corresponding half of the array, and it will compute its sum. Each child will send the partial sums to the parent who will collect and add the partial results. Finally, the parent will print the final sum. (Note: Use arrays of even length).
Expected outputs
Example 1 ./luis 1 1 2 3 4 5 6
Assuming parent has pid 2, and child 1 has pid: 3.
We want to see the following output
>>I am parent with pid: 2 sending the array: 1 2 3 4 5 6 to child with id: 3.
>>I am child with pid: 3, adding the array 1 2 3 4 5 6 and sending partial sum 21.
>>I am the parent pid: 2 receiving partial sum 21 and printing 21.
Example 2./luis 2 1 2 3 4 5 6
Assuming parent has pid 2, child 1 has pid: 3, and child 2 has pid: 4.
>>I am parent with pid: 2 sending the array: 1 2 3 to child with pid 3, and 4 5 6 to child with pid 4.
>>I am child with pid: 3, adding the array 1 2 3 and sending partial sum 6.
>>I am the parent pid: 4, adding the array 4 5 6 and sending partial sum 15.
>>I am the parent pid: 2 receiving partial sum 6 and 15 and printing 21.
Example 3./luis 3 1 2 3 4 5 6
Assuming parent has pid 2, child 1 has pid: 3, child 2 has pid: 4, and child 3 has pid: 5
>>I am parent with pid: 2 sending the array: 1 2 to child with pid 3, 4 5 to child with pid 4, and 5 6 to child with pid 5
>>I am child with pid: 3, adding the array 1 2 and sending partial sum 3
>>I am child with pid: 4, adding the array 3 4 and sending partial sum 7
>>I am child with pid: 5, adding the array 5 6 and sending partial sum 11
>>I am the parent pid: 2 receiving partial sum3, 7, and 11, and printing 21
Currently, I'm not concerned about whether the output looks the same. All I care about is that the programs that run and read the command line as seen in the examples. The program(s) must be written in C, these programs are then compiled in Linux which is where the program should read the command line.
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