in reply to Re^5: Forking child processes.
in thread Forking child processes.

I think what's happening is that the process that calls tick() is exiting before the three exec(@ping_cmd) has a chance to return (which has the effect of only some of the run_on_finish() are getting a chance to run).

The callback now runs for ALL child processes by calling $pm->wait_all_childern;

Since I am waiting on all children, I am probably not creating any defunct processes from tick().. which doesn't really matter since not calling wait_all_children had the effect of exiting immediately and the defunct child processes would have been inherited by init. Is this correct?

sub tick { my $MAX_PROCESSES = 1000; my $pm = new Parallel::ForkManager($MAX_PROCESSES); my @ping_cmd = ("ping", "testhost", "-s 5", "-c 1"); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; my ($check_id, $host) = $ident =~ /^(.*?) on (.*)/s; print "^^^^^^^^^^^run_on_finish: $ident (pid: $pid) exi +ted with code: [$exit_code] host: [$host]\n"; } ); $pm->run_on_start( sub { my ($pid,$ident)=@_; print "** $ident started, pid: $pid\n"; } ); for(my $i=0; $i< @servers; $i++){ my $srv_id = $servers[$i]{id}; my $srv_name = $servers[$i]{name}; $ping_cmd[1] = $servers[$i]{name}; print "$srv_name:\n"; $pm->start("ping on $srv_id") and next; exec(@ping_cmd); print(STDERR "ping on $srv_name exec failed: $!\n"); _exit($!); } print "Waiting for all pings...\n"; $pm->wait_all_children; print "Tick finished.\n"; }