if ( $child = fork ) { #Do Parent stuff here } else { while ( $child2 = fork ) { # fork 2nd child, wait for wait; # it to finish and re-fork } # Do second level child stuff here # Every time we finish, child # 1 starts us again exit; } #### if ( $child = fork ) { close PARENTWRITE; # Not needed in parent while ( ! $child2data ) { $child2data = ; } # Do Parent stuff here # after ensuring that child2 started } else { close PARENTREAD; # Not needed in child # Do some processing while ( $child2 = fork ) { # fork 2nd child, wait for wait; # it to finish and re-fork } # Do second level child init stuff here print PARENTWRITE 1; # Let parent know we started good # Do more second level child processing # Every time we finish, child # 1 starts us again exit; }