Due to short circuit.
If I rewrote this:
main()
{
// fork() && fork() || fork();
if (fork()) {
if (!fork()) {
fork();
}
} else {
fork();
}
printf("forked\n");
return 0;
}
After the first fork, you will have one process that immediately goes into the else branch, and one that continues. The one that goes into the else loop will expand once (right branch). The one that enters the inside will unfold once, and his child will again be a fork.
f
/ \
f f
|
f
source
share