http://www.perlmonks.org?node_id=667049

Hercynium has asked for the wisdom of the Perl Monks concerning the following question:

Magnanimous Monks, myriad musings mottle my moody mind. Maybe many mighty mentors might minister me memorable motions mending my malady? (I've been waiting to post that for months - alliteration is dorky but *fun!*) :)

OK, here's what I came for:

I have a program that forks off a pile of long-running children. Actually, the child processes should probably *never* return or die, in normal operation.

The code I've already written (simplified version below in the readmore section) simply reports info about dead children to a log, but now I need to do more...

The calls to fork are done inside a loop that looks like this:
my %child_info; foreach my $params (@params_for_children) { if ( my $pid = fork() ) { $child_info{$pid} = $params; } else { do_childish_things($params); croak "Child fork exited - should never happen\n"; } } while ( my $pid = wait() ) { last if $pid = -1; my $exit_status = $?; report_dead_child($pid, $exit_status, $child_info{$pid}); }

Generally, this works very well, but there are some things I need to add and I'm somewhat uncertain about how I would best go about it.


SO... I need advice with the following requirements:

My main question is this:

Is the code above a bad way for me to do this?
and,
Should I continue writing my own solution(s) or is there a robust CPAN module that will do this for me with less hassle?