Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming Assignment: Write a program that will accept a number of arguments from the command-line between 1 and 7, inclusive each a unique integer

C Programming Assignment: 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.

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

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

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

Question What is an educational benefit trust and how is it used?

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago