I'm trying to figure why do this statement produce 2 processes
I understand the short circuiting issue, and I know that if this statement was executed without if we will get 4 processes in total. So can you explain the criteria which is used by inserting if to a statement like this.
Best How To :
There should be 4 processes created. You can easily verify this by placing an extra
printf call after the
printf("Hello") is only run twice, because the condition is only true for two of those processes.
Specifically, the root process spawns two child processes, and the second child process spawns one more :
<parent> : condition is true because the two first fork calls return non-0 : (true && (true || ??))
<child1> : condition is false because the first fork returns 0: (false && (?? || ??))
<child2> : condition is true because the first and third fork calls return non-0: (true && (false || true))
<child3> : condition is false because the second and third fork calls return 0: (true && (false || false))