Explore BrainMass

Computer Science: Fork Function

This content was STOLEN from BrainMass.com - View the original, and get the solution, here!

Write a C program that takes an integer argument from the command line and outputs the sum of all digits of the integer. For example, the result of the invocation sum of digits 12345 should be 15.

The program has two constraints:

1) Each process can do at most one addition. If you want to calculate the sum of more than two digits, you will have to fork one or more processes in order to do that, and each of the forked processes in turn can process at most one more addition before forking further more process(es) to compute the sum.

2) Each process can fork at most one other process.

© BrainMass Inc. brainmass.com September 22, 2018, 5:10 am ad1c9bdddf - https://brainmass.com/computer-science/compiler-theory/computer-science-fork-function-525108

Solution Preview

Please find attached an implementation (525108.c) to achieve the goal. Please be aware that this is not the only way to go about it, that is, many approaches are possible in this case.

Attached program has been tested for ...

Solution Summary

GNU C compiler (gcc) version 4.3.4 was used during the development of attached program is in the attached Excel file. It also prints information messages indicating what addition is being performed by which process.