fork() && fork() || fork();
^^^^^^^^^^^^^^^^
Parent forks a child with return value 0 for the child process.
Since it is logical AND operator, the short-circuit evaluation applies,
so the child doesn’t go further. Parent goes on forking again(right-hand-side of AND).
There are 3 processes being composed of 2 children and 1 parent.
fork() && fork() || fork();
^^^^^^
Again parent forks one more and since OR operator
doesn’t apply short-circuit for latter child
(due to return type which is 0 and left-hand-side of OR op.),
the latter child forks as well. There are totally 5 processes.
fork()[fourth]; doubles prior number of processes 5*2 = 10 processes totally exist.
Ваш вывод, скорее всего, буферизован. Попробуйте fprintf(stderr, "forked ");
, fflush(stdout)
или printf("forked\n”);
.
Я думаю, что следующий рисунок помогает больше.