subject

Write a parent program to fork(2) n processes where n is passed tothe program on the command line, and n can be from 1 to 10. All output should bemade with fprintf to the stdout or stderr (followed immediately by an fflush). Follow these directions exactly!

Flag ALL errors, including those returned from any functions with output tothe stderr, or with a call to perror and then exit with the exit(3) function (ifapplicable).In the forked (child) program (recall fork(2) returns 0 to the child process),get the process ID, and current time; using the current time generate arandom wait time between 1 and 10 (seconds). Instead of srand(3) andrand(3), use srandom(3) and random(3) to generate these random numbers, using a seed equal to the current time (type time_t) * the process ID (typepid_t). This guarantees that the seed is different in every child. The child thensleeps for the random number of seconds (see sleep(3)), and returns usingthe exit(3) call with the exit status equal to the number of seconds slept. In the parent (recall fork(2) returns to the parent the process id of the child)save the process IDs in the order returned in an array of process IDs. Theparent then loops through the process ID array and waits for each process IDto exit (using waitpid(2)) in the order in which they were started. To get and display the current time use time(3) with a NULL parameter, andthen call ctime(3) with the value returned by the time(3) call. Use the WIFEXITED and WEXITSTATUS macros on the status returned bywaitpid(2) to determine the return status of children with normal returns(see the text section 8.6). Do NOT use the WNOHANG option with the waitpidcall. Both the parent and child processes will output information to the stdout andstderr.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:00
Select all that apply. what types of documents can be created using word-processing software? business newsletters letters of application presentation slideshows customer databases
Answers: 1
question
Computers and Technology, 21.06.2019 23:30
Me2540 week 5 assignment what do i want to know?
Answers: 1
question
Computers and Technology, 22.06.2019 16:00
Why should characters such as / \ " ' * ; - ? [ ] ( ) ~ ! $ { } < > # @ & | space, tab, and newline be avoided in file names?
Answers: 2
question
Computers and Technology, 22.06.2019 18:00
Which of the following physical laws can make the flow of water seem more realistic? a. motion b. gravity c. fluid dynamics d. thermodynamics
Answers: 2
You know the right answer?
Write a parent program to fork(2) n processes where n is passed tothe program on the command line, a...
Questions
question
Mathematics, 03.10.2019 02:10
question
Chemistry, 03.10.2019 02:10
Questions on the website: 13722363