How many processes does this piece of code create?
for(int i = 0 ; i < 5 ; i++){
if(fork() == fork())
break;
}
How many processes does this piece of code create?
for(int i = 0 ; i < 5 ; i++){
if(fork() == fork())
break;
}
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.