In general for n
forks
in this manner will execute the next statements (in this case printf
) 2^n
times.
Here is how:
|
+-fork()----------------------------------+
| |
+-fork()-------------+ +-fork()-------------+
| | | |
+-fork()---+ +-fork()---+ +-fork()---+ +-fork()---+
| | | | | | | |
print() print() print() print() print() print() print() print()