// start from parent process consider it 1st process
if(fork()&& fork()) // 2 child process created
{
fork(); // 1 child process created
} // in total 1+2+1= 4 process created ( among which 1 parent and 3 child process )
from 1 parent process
if( fork() || fork() ) // 2 child process is created here from above parent process ,
// it is short circuit so in case of OR (||), after evaluation of left operand, right operand will be evaluated only if left operand evaluates to zero. But here left operand gives value 2( 21 = 2 by using the formula {2n -1 }+1 where n =1 ) so right operand is not evaluated.
{
fork(); // 2 child process is created
fork(); // again 2 child process is created
} // for each of fork() call in OR (||) 4 child process created , there are 2 fork() so total 4+4 = 8 child process created
// so in total ( 2+2) + (2 +2) = 8 [ for each fork() call in if() condition created 4 child process so total 4+4 = 8 child process ]
Total number of process created = 4 * ( 1+8) = 4 * 9 = 36 [add 1 for parent process ]
so total 36 times "GATE 2017" will be printed .