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:
- If a child dies, a new one needs to be spawned, with
the same parameters as it's predecessor, but not
immediately - there should be about a 1 min
delay.
- If a child dies twice within a short period (say 5
min) it should be restarted after a longer (say 10
min) delay.
- If a child dies X number of times, the parent should
do some pre-defined action (like emailing me) and
give up on that child.
- These delays should not cause the parent to miss
opportunities to revive other dead children
- If the parent is terminated, all the children need
to die with it.
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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.