loop infinitely have a nested loop that iterates n times (in this case 10) within the nested loop there is a conditional fork (fork on 6th loop) sleep after completing the nested loopInstead it proceeds as expected initially but after a few (2) iterations there are mutliple children which execute simultaneously... The problem goes away if I remove the CHLD handler, but then I have zombie children... If I set CHLD to IGNORE the problem goes away (though I always have *one* zombie)
It seems to be related to the fact that it is somehow running through the nested loop multiple times?
Looping 6 (28680) ... I am child 28682 [0] Looping 6 (28680) ...Any ideas?
sub REAPER { $waitedpid = wait; print "GOT PID: $waitedpid\n"; $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; while(1){ my $i=0; print scalar localtime(time()), "\n"; for(;$i<10;$i++){ print "Looping $i ($$) ...\n"; if( $i == 5 ){ if( ! defined($pid = fork) ){ print "Danger danger Will Robinson!\n"; } unless( $pid ){ print "I am child $$ [$pid]\n"; exit 0; } } } sleep 5; }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |