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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|