CS FundamentalsHardWipro Elite · LTIMindtree

How many processes (including the original one) exist after this program runs to completion?

How many processes (including the original one) exist after this program runs to completion?
fork();
if (fork()) {
    fork();
}
  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 8

Correct answer: C. 6

The first fork() gives 2 processes. Each of them then calls fork(); the parent gets a nonzero value and calls fork() again, while the child skips it. Each process thus produces itself + 2 children = 3, so 2 x 3 = 6.

More Operating Systems questions

Exams that ask this topic