Answered step by step
Verified Expert Solution
Link Copied!

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 5.
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 (e.g., 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:
$ ./parallel_execution
Enter the number of child processes to create: 3
Parent process (PID: 1234) is creating 3 child processes.
Child 1(PID: 1235) is computing the factorial of 5.
Child 2(PID: 1236) is finding prime numbers up to 20.
Child 3(PID: 1237) is performing a custom task.
Child 1(PID: 1235) completed its task. Result: 120
Child 2(PID: 1236) completed its task. Result: 235711131719
Child 3(PID: 1237) completed its task. Result: Custom task completed.
All child processes have completed. Parent (PID: 1234) 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 (e.g. 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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Do you have any future plans for marriage and children?

Answered: 1 week ago