Machine-translated by Google. Questions are authored in English.
Top

Discussion

The number of child processes are created using the following code :

int main()
{ fork(););
  fork();
  fork();
  return 0;
}

  • A.5
  • B.6
  • C.7
  • D.8

Answer: C

The code creates 7 child processes.

Each fork() duplicates every process that executes it, so the number of processes doubles with each call. After three calls there are

\[ \begin{aligned} 2^{3} &= 8 \text{ processes} \\ &= 1 \text{ parent} + 7 \text{ children} \end{aligned} \]

The first line as printed has a stray ');' after the first call, which a compiler would reject; the question intends three successive fork() calls. 8 counts the original parent as well, and 5 and 6 do not arise from doubling.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.