Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to do this in c or c++ Write a program to demonstrate the use of fork() and wait() system calls on Unix/Linux machines.

I need to do this in c or c++ image text in transcribed
Write a program to demonstrate the use of fork() and wait() system calls on Unix/Linux machines. The program should perform exactly 15 iterations before terminating. In each iteration, the program will create 10 child processes (p0 to p9). Each process will print its decimal digit (0, 1, .., 9) once without newline before exiting, that is all the children processes will do. After creating the 10 children in each iteration, the parent (original process) will wait until all its 10 children have completed, then it will print a new line before going to the next iteration or exiting. The output of this program, when properly implemented, will illustrate the unpredictable order in which the processes are scheduled to run. Do not have 10 explicit calls to the fork) function. Use a loop with only one instance of the fork() call in your program. Two sample outputs of the program are provided below. Your output should look similar. In order to wait for all the children to complete, use wait(NULL) in a loop until the return value of wait(NULL) is -1, which means all the children have completed. 985 6724 3 1 0 8 1 4 9765 3 2 0 2 789 6 5 4 3 1 0 0 1 39 874 2 6 5 8 7 65 3 2 0 1 49 2 145 367 8 0 9 0 1 2 3 4567 9 8 0 1 2 4 35 6789 0 1 2 3 5 46789 98 5 4 3 20 7 6 1 0 1 2 3 6785 9 4 0 1 42 685 379 0 1 2 3 456789 6 7 95 4382 1 0 2 394 567081 2 6 3 1 45789 0 3 2 45 1 7 68 90 3 2 4 5 1 7 6 8 9 0 3 245 81 67 9 0 3 2 6 4 5 17 890 3 24 1 567 89 0 3 452 6 178 9 0 4 7 5 3 6 2 8910 4 25 3 678 9 1 0 4 3 5 8 6 2 7 9 1 0 3 462 5 1 7890 5 746 3 8 2 1 9 0 6 8 5 7 4103 9 2 6 7 8 9 5 4 2 3 1 0 6 7 3 8 9542 1 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions