Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment description : Task: Write a C program that simulates a parallel task execution scenario using process forking. The program should create a specified number
Assignment description :
Task:
Write a C program that simulates a parallel task execution scenario using process forking. The program should create a specified number of child processes, each performing a unique task. The parent process should wait for all child processes to complete before displaying the final result.
Requirements:
Your program should take an integer input n from the user, where n represents the number of child processes to be created. n should be less than
Each child process should perform a different task, such as computing the factorial of a number, finding prime numbers in a range, or any computationally intensive operation.
The parent process should display a message before creating forking the child processes.
Each child process should print its own identifier PID and the task it is performing.
After completing their tasks, each child process should print a completion message.
The parent process should wait for all child processes to finish before displaying a final message.
Additional Considerations:
Use the fork system call to create child processes.
You may use other relevant system calls or functions as needed eg wait exit
Ensure proper error handling for system calls.
Design the code to guarantee the creation of exactly n children, ensuring that each child executes its intended task. Properly manage the process creation to avoid any unintended duplication or omission of child processes.
Submission Guidelines:
Submit the C source code along with a brief report explaining the design choices and the lessons learned during the implementation. Discuss any challenges encountered and how they were addressed.
Sample output:
$ parallelexecution
Enter the number of child processes to create:
Parent process PID: is creating child processes.
Child PID: is computing the factorial of
Child PID: is finding prime numbers up to
Child PID: is performing a custom task.
Child PID: completed its task. Result:
Child PID: completed its task. Result:
Child PID: completed its task. Result: Custom task completed.
All child processes have completed. Parent PID: is displaying the final message.
Questions?
if you have any questions or you need help with code please contact your TA and attend the weekly lab sessions.
Deliverables:
your C source code eg myfirstlastname.c and PDf report.
Remember to include the following as a comment at the beginning of your program:
Your name
Your panther ID
GETTING STARTED:
you can use this Download thiscode to get started.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started