Question #31: The system call fork() returns PID for the parent but returns 0 for the child. How many total processes will be spawned after executing following program?
int main()
{
fork();
fork();
}
A) 2
B) 3
C) 4
D) 1
Solution: After first fork(), we have two processes, let’s say A(parent) and B(child). Now, both A and B will fork one child each, hence totaling 4 processes. Therefore, the correct answer is C.