Given statements ,
- void main( ) {
- fork( );
- fork( );
- exit( );
- }
At line #2,
one child process will be created.
Now we have total 2 processes, 1 child process and another parent,
And the next statement to execute is line#3 in both processes.
At line #3
Now both processes(1 parent and 1 child process) executes line#3 , and this will create two child processes.
One created by parent , And another by child (which was earlier created at line #2).
So,
total child processes are 1(line#2) + 2(line#3) → 3 child processes
General formula for calculating no. of child processes (2^n) -1 (unless the fork is not called upon any condition)