CS350 Midterm: S14-midterm-sol.pdf

65 views7 pages
8 Oct 2014
Course
Professor

Document Summary

Consider the application code below, which uses the fork and waitpid system calls. int i; dofork() { pid t pid; int status; i++; pid = fork(); if (pid == 0) { /* child */ printf(%d,i); return; Four processes: (2 marks) show the output that will be produced when this program runs. Note that the state- ment printf(%d,i); will print the value of integer variable i. You should show the combined output of all processes. Your answer should be a single sequence of numbers. 1 2 1 0 1 0: (2 marks) suppose that the call to waitpid is removed from the dofork function, and the modi ed program is then run. Give an example of output that could be produced by this modi ed program, but that could not be produced by the original, unmodi ed program. Again, your answer should be a single sequence of numbers.