-1

How many processes does this piece of code create?

for(int i = 0 ; i < 5 ; i++){
    if(fork() == fork())
    break;
}
tugayicoru
  • 39
  • 3

1 Answers1

0

The first parent spawns five children. Each of those spawns four children. Each of those spawns three children, and so on.

So it's:

5 * (1 + 4 * (1 + 3 * (1 + 2 * (1 + 1))))

Looks like 325 processes spawned, plus the original one.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436