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, 22.06.2019 19:10
10. when you create a pivottable, you need to specify where to find the data for the pivottable. is it true
Answers: 2
question
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in              a.  advanced mode.    b.  automatic mode.    c.  basic mode.    d.  typeover mode
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
Worth 50 points answer them bc i am not sure if i am wrong
Answers: 1
question
Computers and Technology, 24.06.2019 10:30
You're programming an infinite loop. what must you include in your code to prevent crashes? in roblox
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, 07.04.2020 23:24
question
Mathematics, 07.04.2020 23:24
Questions on the website: 13722361