Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i ) parent 1 . The main ( ) will access the command line argument name of a text file. If there is no argument,

i) parent
1. The main() will access the command line argument name of a text file. If there is no argument, it should write
a usage message (indicating how to use this program) and terminate. Otherwise, it should recover the argument.
2. In the beginning, you will do the same thing as you did in the first step of Part I, i.e., read the list of numbers from
the data file and, again, sort the list within the program in ascending order using the same sorting technique as
you used in Part I.
COMP-3300 Page 2
3. Now the main() will fork off five child processes using fork() system call and pass the list to each of the
newly created child processes. Call these children child1, child2... child5 such that each child process will
process ONLY 1/5 th of the numbers in the list. However, before passing control to the child processes, the parent
process will print the following message:
I am the father of the following: ...,...,...,..., and ...
where ... represents the process id of each of the five children.
[HINT: Think of how the child process will know about the first number in the list from which it has to start
processing the list, perhaps a pipe or perhaps a simple shared variable will do it? Does it need to know the last
number too or could it simply finish after processing 25 numbers? Think carefully to come up with the solution.]
4. Will wait for all five of its children to complete.
5. On termination of each child, will report the event by printing the following message on screen:
From the main: child, id =... ended with status...
where the first set of dots is the pid of the child and the second set of dots represent the termination status of the
child.
6. Parent will calculate the CPU time it takes to do the entire set of steps (including that of child processes),
print the CPU time and then will terminate after printing the message Good bye!.
ii) Children:
On its turn, each child will start its execution. Each child process will calculate the persistence of each of the number
in its portion of the sorted list and will find the number with the smallest and the largest persistence values and print
both the numbers and their corresponding persistence values followed by the following message:
I am kid #: ... and my id is: ...
Where the first set of dots is the child # (1,2,3,4 or 5) and the second set of dots is the pid of itself. After copying
the file, it will terminate its execution with the exit() system call by providing some arbitrary integer m (m>=1) as
an argument to the exit() system call.

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

More Books

Students also viewed these Databases questions