Question discussion

How many processes (including the original one) exist after the following statement is executed?if (fork() && fork()) fork();

2109Medium DSSSB TGT Computer Science 0 replies 1 views
0

How many processes (including the original one) exist after the following statement is executed?

if (fork() && fork()) fork();
  • A4
  • B3
  • C5
  • D6
Correct answer: A

Explanation

In the child of the first fork() the value is 0, so && short-circuits; only the parent evaluates the second fork(), whose child gets 0, while the parent (non-zero) executes the third fork(): original parent, 3 children = 4 processes.

Discussion 0

Nobody has replied yet. Start the discussion!