How about catching the SIGCHLD messages and using that
as your trigger to start the process again. Something along
these lines.
#!/usr/bin/perl -w
use strict;
launch_child();
$SIG{CHLD}=\&launch_child;
sleep 60 while(1);
sub launch_child{
print "$$ parent spawning a child\n";
my $pid=fork;
if(!$pid){
print "$$ inside the child\n";
# all the code that does the real work is in here
# all the other stuff is just a wrapper to keep
# this bit going
sleep 60 while(1);
}
}
If you really care about your process
you'll back this up with some of the methods mentioned above.
You may also want to put some checks on to keep
the process from thrashing (constantly restarting the process,
which immediately dies again, etc...) just in case.
This technique does have the nice side-effect that the
restarts are nearly instentaneous.
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.