Question: In this project you will be writing a C program that forks off a single child process to task. The main process will wait for
In this project you will be writing a C program that forks off a single child process to task. The main process will wait for it to complete and then do some additional work.
Your program should be called mathwait.c and it will be called with a filename followed by a series of numbers. So for example:
mathwait tempfile.txt
Optionally, your program should also take in one option:
h : This should output a help message indication what types of inputs it expects and what it does. Your program should terminate after receiving a h
After processing and checking for h your program should then call to fork The parent process should then wait until the child process has finished.
What the child process should do:
The child process will take all the numbers from the command line arguments and put them into a dynamic array of a large enough size for those numbers.
Once this is done, you should then open the file you were given for writing and then write all the numbers to the file. However, whenever the child writes to the file, it should write it in the following format:
Child: PID: Data
So for example, if the PID of our child process is we would write to the file:
Child: :
It should then process this array to see if any two of the numbers sum up to
Your process should then output any pairs that sum up to in the file, so in our file we would output:
Child: : Pair: Pair:
Note that the pairs can be in any order, as long as you list all the possible pairs. Once complete, the child process should close the file, free the dynamic array and terminate. It should give EXITSUCCESS if it found at least one pair that summed up to and an EXITFAILURE if it found none.
What the parent process should do:
After forking off the child process, the parent process should wait call waiting for the child to end. It should then check the status code returned from the child process and write that to the file. For example, assuming its process ID was and it got EXITSUCCESS:
Parent: : EXITSUCCESS
For this project, you only need one source file mathwaitc and your Makefile.
Please show the mathwait.c file and the Makefile. Thank you.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
