Hello!
I am trying to write a preforking server and have got a copy of exactly what I need from the Perl cookbook (Chapter 17). After a few teething problems where the server kept forking more and more children (I checked the result of wait in REAPER being greater than -1 before decrementing the number of children left)
sub REAPER
{ # takes care of dead children
$SIG{CHLD} = \&REAPER;
my $pid = wait;
if ($pid > -1)
{
$children --;
print "child $pid died, only $children left\n";
delete $children{$pid};
}
else
{
$children = 0;
}
}
This appears to work, except that the master process does not appear to be being woken up from its sleep when a child dies:
# And maintain the population.
while (1)
{
sleep; # wait for a signal (i.e., child's death)
print "got woken up by signal\n";
for ($i = $children; $i < $PREFORK; $i++)
{
make_new_child(); # top up the child pool
}
}
The master process only appears to be woken up when the last of the children dies - resulting in the master spawning all the children at once - not what I was after. Interestingly, I've copied the script to a Mandrake 9 machine, and found that the sleep is interrupted at the point a child dies. However, I found a different problem there in that my client script fell over with
IO::Socket::INET: connect: Cannot assign requested address
So, is there a problem with signals on HPUX or is the example given a bit naive?
Many thanks
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.