Question: Consider the following program: 1 2 #include #include 3 using namespace std; 4 5 int main() 6{ 8 90 10 cout < < Hello
Consider the following program: 1 2 #include #include 3 using namespace std; 4 5 int main() 6{ 8 90 10 cout < < "Hello world! "; if(fork()) { fork(); } else { fork(); cout < < "Just completed a fork "; cout < < "All done...goodbye! "; return 0; 11 12 13 14 } 15 16 17 18 } 19 18 } 19 Answer the following questions assuming the above program is executed once. Note: for questions that ask for a line number, please use a single digit for your answer (e.g., 1, 4, 8, etc.) 1. How many times does "Hello world!" get printed on the console? 2. How many times does the fork() function in Line 9 get executed? 3. Which process (parent process or child process) executes Line 10? 4. How many times does "Just completed a fork" get printed on the console? 5. How many times does "All done...goodbye!" get printed on the console? Hints: . . You will need to think about what process hierarchy gets generated by this program Pay attention to the evaluation of the if condition Make sure to consider different behavior in the parent and child processes involved in each fork
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
