Question: Write a program that will accept a number of arguments from the command-line between 1 and 7, inclusive each a unique integer between 0-9. The
Write a program that will accept a number of arguments from the command-line between 1 and 7, inclusive each a unique integer between 0-9.
The program (parent process) will request shared memory for these integers, attach the shared memory to its own address space and fill the space (using an array) with the integers from the command-line. The parent will display the initial state of the shared memory and then spawn a number of child processes equal to the number of command-line arguments, all at once, and then wait for each and every child to complete its tasks. Upon completion of all children, the parent will acknowledge said completion by storage and display of their respective exit codes, display the final state of the shared memory, detach the shared memory, remove the shared memory, and then terminate. Each child process will receive a unique ID upon initiation an integer between 1 and the number of command-line arguments (maximum 7).
Each child will display the initial state of the shared memory and their private memory - their unique ID. Next each child will locate the array element (index) associated with their unique ID and then multiply that array element by their unique ID, storing the result in the same array element. Each child will then display the current state of the shared memory, provide their exit status/code, and exit.
Output: Each step (function?) that a process (parent or child) takes (starting, validating, requesting/removing shared memory, attaching/detaching shared memory, forking/completing child processes, exiting, etc.) will output a trace statement in order to show which statements are currently being executed. The parent will prefix each trace statement with Parent: and each child will prefix their trace statements with a tab (or spaces) and then Child ID: , where ID is their unique ID, so that the child output stands out from the parent output. Consider buffered versus un-buffered output.
Input: Command-line input will be validated, as normal.
Requirements: Style requirements as discussed in class expected. Efficiency should always be considered. Always select the most appropriate loop/decision structures and variable/constant types. Functions should focus on a single task. Main() should be high-level tasks only.
Command-line could look something like:
$ ./SharedProcess 1 2 3 4 5 6 7
Document compilation/execution and command-line requirements in your program header.
Appropriate error handling should be included for the spawning of processes and for each step of the shared memory process. Refer to the Process Control and Fork() links on Moodle for details and options in spawning processes and sharing memory.
User header file is recommended.
Use of MakeFile is required for this assignment. Provide a make build target or allow make to compile your programs. Do not have your Makefile execute, only compile.
Submission: Your program must be able to compile/link and execute on FIU SCIS, using gcc. Test it there before you submit.
Your source code file name(s) should be documented in the first line in your programs. Include Main in your source code file name for the source code file(s) that includes a main().
Refer to the Moodle documents: How to Develop a Simple C Program and Style Guide for details on required program format and documentation. Review both documents carefully! Document any compiler warnings that are not resolved.
Algorithm (pseudocode) should be submitted in a separate text file and included with the Moodle posting and class submission.
Print out a copy of your source code file, header file, Makefile code and pseudocode and submit in class signed, stapled and collated in the specified sequence: primary source code (w/main) file, additional source code file(s), header file(s), Makefile code file, and then the pseudocode text file.
Post a .zip file with all source code (.c) files, user-defined header file (.h), Makefile, and text files on the Moodle web site.
Program documentation must include the required signed disclaimer (comment) in the heading no grade will be assigned to programs that omit the disclaimer or signature.
Sample trace statements output - numeric output not displayed, output will vary with each run
Parent: starts
Parent: validate command line
Parent: requests shared memory
Parent: receives shared memory
Parent: attaches shared memory
Parent: fills shared memory
Parent: displays shared memory
Parent: forks (each) child process
Child ID: # starts
Child ID: # displays shared memory
Child ID: # displays private unique ID
Child ID: # updates shared memory
Child ID: # displays shared memory
Child ID: # exits with code
. . .
Parent: waits for (each) child
Parent: detects (each) child completion
Parent: displays (each) child exit code
Parent: display shared memory
Parent: detaches shared memory
Parent: removes shared memory
Parent: finished
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
