Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 24.06.2019 04:30, shadenShaden2037
What is the process in which the software development team compiles information to determine the final product
Answers: 1
image
Computers and Technology, 25.06.2019 06:50, gutierrezaandrea56
The federal sentencing guidelines for organizations set the tone for organizational ethics compliance programs by question 1 options: a) codifying into law incentives for organizations to take action such as developing ethical compliance programs to prevent misconduct. b) forcing all organizations to develop mandatory reporting systems and ethics programs. c) eliminating most of the federal legislation that created inefficient and time-consuming activities for businesses. d) providing detailed guidelines for how to set up organizational ethics programs to guard against unethical conduct. e) providing a thorough examination of company codes of ethics to determine whether they are sufficient.
Answers: 1
image
Computers and Technology, 25.06.2019 09:30, mustafajibawi1
1. write a statement that declares a string variable named city. the variable should be initialized so it references an object with the string “san francisco”. a) assume that stringlength is an int variable. write a statement that stores the length of the string referenced by the city variable (declared in question1) in stringlength. b) assume that onechar is a char variable. write a statement that stores the first char- acter in the string referenced by the city variable (declared in question1) in onechar. c) assume that uppercity is a string reference variable. write a statement that stores the uppercase equivalent of the string referenced by the city variable (declared in question 1) in uppercity. d) assume that lowercity is a string reference variable. write a statement that stores the lowercase equivalent of the string referenced by the city variable (declared in question 1) in lowercity.
Answers: 3
image
Computers and Technology, 25.06.2019 22:00, cvvalle15
Drag the tiles to the correct boxes to complete the pairs. match the items with their respective descriptions.
Answers: 2
Do you know the correct answer?
Write a parent program to fork(2) n processes where n is passed tothe program on the command line, a...

Questions in other subjects:

Konu
Mathematics, 26.12.2019 13:31