CS FundamentalsVery hardGATE CS

How many processes exist at the end, including the original? (Every fork() succeeds.)

How many processes exist at the end, including the original? (Every fork() succeeds.)
fork() && (fork() || fork());
fork();
  1. A. 8
  2. B. 16
  3. C. 7
  4. D. 6

Correct answer: A. 8

In the first line the child of the first fork short-circuits (0 && …). The parent forks again: it gets non-zero and stops, while that child evaluates the third fork. That gives 4 processes, and the last fork() doubles them to 8. 16 ignores short-circuiting; 7 counts only the new processes.

More Operating Systems questions

Exams that ask this topic