Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a multi-processed program using the fork() call which will take in parameters from the command line and calculate the sum of the numbers. In

Write a multi-processed program using the fork() call which will take in parameters from the command line and calculate the sum of the numbers. In doing so, there will be three processes. The parent process will start by setting up the necessary pipes for communication. Then, it will spawn 2 child processes (C0 and C1). The parent process will then parse the entries passed in as arguments. If the value entered is even, it will be piped to C0 to be summed. If it is odd, it will be piped to C1 to be summed. As each child process receives a number, it will add the number to the sum of numbers it has received. Once all numbers have been parsed and sent via pipes to the child processes, the parent will close the pipes to the child processes. The child processes will then write their sum in the pipes going back to the parent process and all processes will exit.

Sample output:

ex13 1 3 5 7 9 2 4 6 8 10

1 added by C-1 to make a sum of 1 3 added by C-1 to make a sum of 4 5 added by C-1 to make a sum of 9

7 added by C-1 to make a sum of 16 9 added by C-1 to make a sum of 25 2 added by C-0 to make a sum of 2 4 added by C-0 to make a sum of 6 6 added by C-0 to make a sum of 12 8 added by C-0 to make a sum of 20 10 added by C-0 to make a sum of 30 P received subtotal of 30 from C-0.

P received subtotal of 25 from C-1. P indicates the total is 55.

ex13 2 4 6 8 10 12 14 16 18 20

2 added by C-0 to make a sum of 2 4 added by C-0 to make a sum of 6 6 added by C-0 to make a sum of 12

8 added by C-0 to make a sum of 20

10 added by C-0 to make a sum of 30

12 added by C-0 to make a sum of 42

14 added by C-0 to make a sum of 56

16 added by C-0 to make a sum of 72

18 added by C-0 to make a sum of 90

20 added by C-0 to make a sum of 110

P received subtotal of 110 from C-0.

P received subtotal of 0 from C-1.

P indicates the total is 110.

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 Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions