Question 84: What will be the output of the following program:
if ( fork() )
{ printf(“Parent Process\n”);
wait(NULL);
printf(“Waited for child\n”);
}
else
{ printf(“Child Process\n”);
}
1. Parent Process
Child Process
Waited for child
2. Child Process
Parent Process
Waited for child
3. Parent Process
Waited for child
Child Process
4. Both A and B are possible
Solution: Since both parent and child process can execute first depending on the scheduling policy, it is indeterminate. The only thing is that child process has to be killed before parent can go ahead of wait(). The correct answer is option 4.
