Objective Create a program which adds 100 random numbers together and prints the result using multiple child processes using C++ or C. The Child Program Each random number will be created by a child process (a separate program) and returned as the exit status. 1. Create a child program that generates a random number between 1 and 100 (inclusive). 1. If you are using C++, you might consider std::mt19937 2. This is a Mersenne Twister which generates 32-bit numbers with a state size of 19937 bytes. 3. See: 4. 5. https://en.wikipedia.org/wiki/Mersenne_Twister Links to an external site. 2. Your program should introduce a delay within a random interval of 200-600 microseconds. 1. You may utilize usleep(3) for this delay. 3. Your program will return the generated number as the exit status from the main() function. 1. You can return this value. 2. You can also pass it as a parameter to exit(2) 4. You can test your program by running it from the shell. 1. Echo '$?' in the shell to display the exit status of the last executed program. The Parent Program The parent program will create 100 child processes, each running the program created above. 1. You must create all 100 processes before doing anything else. 1. The fork(2) and execve(2) system calls should be used. 2. After creating ALL of the child processes, the parent program will wait for each child to exit. 1. Your children will exit in a random order. 2. Use the wait(2) system call to obtain the exit status. 3. Add this to your running total. 4. Keep track of how many children are still running (or how many have exited) 3. After ALL of the child processes have exited, print out the sum of their generated values. The 2 programs need to have the following: 1. Process Creation and Termination 1. Proper creation and termination of the child processes 2. Ensuring that all child processes exit gracefully. 3. Properly waiting on ALL children 2. Execution of the Child Program 1. Correct generation of random return values and delay times 2. Proper delay using usleep(3) 3. Collection and Display of Results 1. Properly collecting the values from the children and displaying the sum. 2. Properly exiting the parent (without hanging or leaving children running) 4. Code Structure 1. Good quality code with appropriate functions, variable names, and comments. 5. Error Handling 1. Checking for errors from system calls. 2. Proper error messages if they occur.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 I have a mac and use terminal. Please give me step by step instructions+explanation and answer to this problem! Please include the commands to compile etc in terminal and in the order I need to run commands/compile!! 

Objective
Create a program which adds 100 random numbers together and prints the result using
multiple child processes using C++ or C.
The Child Program
Each random number will be created by a child process (a separate program) and returned as
the exit status.
1. Create a child program that generates a random number between 1 and 100
(inclusive).
1. If you are using C++, you might consider std::mt19937
2. This is a Mersenne Twister which generates 32-bit numbers with a state
size of 19937 bytes.
3. See:
4.
5.
https://en.wikipedia.org/wiki/Mersenne_Twister
Links to an external site.
2. Your program should introduce a delay within a random interval of 200-600
microseconds.
1. You may utilize usleep(3) for this delay.
3. Your program will return the generated number as the exit status from the main()
function.
1. You can return this value.
2. You can also pass it as a parameter to exit(2)
4. You can test your program by running it from the shell.
1. Echo '$?' in the shell to display the exit status of the last executed
program.
The Parent Program
The parent program will create 100 child processes, each running the program created above.
1. You must create all 100 processes before doing anything else.
1. The fork(2) and execve(2) system calls should be used.
2. After creating ALL of the child processes, the parent program will wait for each child
to exit.
1. Your children will exit in a random order.
2. Use the wait(2) system call to obtain the exit status.
3. Add this to your running total.
4. Keep track of how many children are still running (or how many have
exited)
3. After ALL of the child processes have exited, print out the sum of their generated
values.
Transcribed Image Text:Objective Create a program which adds 100 random numbers together and prints the result using multiple child processes using C++ or C. The Child Program Each random number will be created by a child process (a separate program) and returned as the exit status. 1. Create a child program that generates a random number between 1 and 100 (inclusive). 1. If you are using C++, you might consider std::mt19937 2. This is a Mersenne Twister which generates 32-bit numbers with a state size of 19937 bytes. 3. See: 4. 5. https://en.wikipedia.org/wiki/Mersenne_Twister Links to an external site. 2. Your program should introduce a delay within a random interval of 200-600 microseconds. 1. You may utilize usleep(3) for this delay. 3. Your program will return the generated number as the exit status from the main() function. 1. You can return this value. 2. You can also pass it as a parameter to exit(2) 4. You can test your program by running it from the shell. 1. Echo '$?' in the shell to display the exit status of the last executed program. The Parent Program The parent program will create 100 child processes, each running the program created above. 1. You must create all 100 processes before doing anything else. 1. The fork(2) and execve(2) system calls should be used. 2. After creating ALL of the child processes, the parent program will wait for each child to exit. 1. Your children will exit in a random order. 2. Use the wait(2) system call to obtain the exit status. 3. Add this to your running total. 4. Keep track of how many children are still running (or how many have exited) 3. After ALL of the child processes have exited, print out the sum of their generated values.
The 2 programs need to have the following:
1. Process Creation and Termination
1. Proper creation and termination of the child processes
2. Ensuring that all child processes exit gracefully.
3. Properly waiting on ALL children
2. Execution of the Child Program
1. Correct generation of random return values and delay times
2. Proper delay using usleep(3)
3. Collection and Display of Results
1. Properly collecting the values from the children and displaying the sum.
2. Properly exiting the parent (without hanging or leaving children running)
4. Code Structure
1. Good quality code with appropriate functions, variable names, and
comments.
5. Error Handling
1. Checking for errors from system calls.
2. Proper error messages if they occur.
Transcribed Image Text:The 2 programs need to have the following: 1. Process Creation and Termination 1. Proper creation and termination of the child processes 2. Ensuring that all child processes exit gracefully. 3. Properly waiting on ALL children 2. Execution of the Child Program 1. Correct generation of random return values and delay times 2. Proper delay using usleep(3) 3. Collection and Display of Results 1. Properly collecting the values from the children and displaying the sum. 2. Properly exiting the parent (without hanging or leaving children running) 4. Code Structure 1. Good quality code with appropriate functions, variable names, and comments. 5. Error Handling 1. Checking for errors from system calls. 2. Proper error messages if they occur.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education