Subject: | Program quits after 64 launches under Windows |
Here you can find a fix to make Schedule::Cron work on a Windows
platform using activeperl distribution (5.8.4 and above).
On windows fork is emulated with threads, handler defined for $SIG
{'CHLD'} is never called. Perl can't handle more than 64 "zombies"
waiting for the parent to get the return code. When the 65th
terminates, the main program quits with no error message.
All we need is to acknowledge regularly for terminated sub processes
using the waitpid function.
Under windows REAPER function has to deal with negative pids to clean
STARTEDCHILD hash.
As a patch, I send you as an attachment a replacement code for
functions REAPER and _cleanup_process_list. It makes this module works
under both UNIX and Windows.
Subject: | Cron_patch.txt |
sub REAPER {
if ($HAS_POSIX)
{
while (my $kid = waitpid(-1, WNOHANG))
{
if (defined $STARTEDCHILD{$kid})
{
$STARTEDCHILD{$kid} = 0;
dbg "REAPER: Child $kid cleanned";
}
}
}
else
{
my $waitedpid = 0;
while($waitedpid != -1) {
$waitedpid = wait;
if (defined $STARTEDCHILD{$waitedpid})
{
$STARTEDCHILD{$waitedpid} = 0;
dbg "REAPER: Child $waitedpid cleanned";
}
}
}
}
sub _cleanup_process_list {
REAPER() if ($HAS_POSIX);
for my $k (keys %STARTEDCHILD) {
delete $STARTEDCHILD{$k} unless $STARTEDCHILD{$k};
}
}