fork() in C program
I think there are 8 processes in total, or 7 descendents of the original, or 3 direct children of the original (the others are grand-children and great-grand-children).
- After the first
fork()
, assuming no failures (throughout), there are two processes. - Each of those executes
fork()
again - so there are now four processes. - Each of those executes
fork()
again - so there are now eight processes.
fork()
results in both the original process and one child to start from that point in the code. Therefore you have this picture: