J
Jorge
All,
I've got a process that creates some children and want to be alerted
when they die. To do this, the SIGCHLD signal is registered in the
process using sigaction to jump to a subprogram as soon as it's
received.
The problem comes when many children exit at the same time and their
father seems to miss some of them. This happens quite often, but not
always.
Why are the signals being missed? I'm pretty sure it's something with
the flags on sigaction, but I've tryed several options and it's always
the same.
I appreciate your suggestions. Thanks in advance.
PS: Perl 2.5.1, hpux 11.00
CODE----------------
#!/bin/env perl
use strict;
use POSIX;
# empty set
my $sigset = POSIX::SigSet->new;
# sigaction structure
my $newaction = POSIX::SigAction->new( 'my_handler', $sigset,
SA_NODEFER);
my $oldaction = POSIX::SigAction->new;
my $return;
sub my_handler
{
my($sig) = @_;
my($hpid) = wait();
$return = POSIX::WEXITSTATUS($?);
print "Im $$. Caught a SIG$sig from $hpid returning $return\n";
sleep(10);
print "Ending handler of $hpid\n";
}
sigaction(SIGCHLD, $newaction, $oldaction);
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
print "Im father process $$\n";
sleep(20);
exit(0);
SOME CUT&PASTE FROM THE TERM---------- as you can see only 4 signals
out of 5 are detected
$ dwmanager_v4_en.pl
Im 6406 sleeping 3 s
Im 6407 sleeping 3 s
Im 6408 sleeping 3 s
Im 6409 sleeping 3 s
Im father process 6405
Im 6410 sleeping 3 s
Im 6406 returning 7
Im 6405. Caught a SIGCHLD from 6406 returning 7
Im 6408 returning 7
Im 6407 returning 7
Im 6409 returning 7
Im 6405. Caught a SIGCHLD from 6409 returning 7
Im 6410 returning 7
Im 6405. Caught a SIGCHLD from 6408 returning 7
Im 6405. Caught a SIGCHLD from 6410 returning 7
Ending handler of 6410
Ending handler of 6408
Ending handler of 6409
Ending handler of 6406
$
I've got a process that creates some children and want to be alerted
when they die. To do this, the SIGCHLD signal is registered in the
process using sigaction to jump to a subprogram as soon as it's
received.
The problem comes when many children exit at the same time and their
father seems to miss some of them. This happens quite often, but not
always.
Why are the signals being missed? I'm pretty sure it's something with
the flags on sigaction, but I've tryed several options and it's always
the same.
I appreciate your suggestions. Thanks in advance.
PS: Perl 2.5.1, hpux 11.00
CODE----------------
#!/bin/env perl
use strict;
use POSIX;
# empty set
my $sigset = POSIX::SigSet->new;
# sigaction structure
my $newaction = POSIX::SigAction->new( 'my_handler', $sigset,
SA_NODEFER);
my $oldaction = POSIX::SigAction->new;
my $return;
sub my_handler
{
my($sig) = @_;
my($hpid) = wait();
$return = POSIX::WEXITSTATUS($?);
print "Im $$. Caught a SIG$sig from $hpid returning $return\n";
sleep(10);
print "Ending handler of $hpid\n";
}
sigaction(SIGCHLD, $newaction, $oldaction);
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
if (!fork())
{
print "Im $$ sleeping 3 s\n";
sleep(3);
print "Im $$ returning 7\n";
exit(7);
}
print "Im father process $$\n";
sleep(20);
exit(0);
SOME CUT&PASTE FROM THE TERM---------- as you can see only 4 signals
out of 5 are detected
$ dwmanager_v4_en.pl
Im 6406 sleeping 3 s
Im 6407 sleeping 3 s
Im 6408 sleeping 3 s
Im 6409 sleeping 3 s
Im father process 6405
Im 6410 sleeping 3 s
Im 6406 returning 7
Im 6405. Caught a SIGCHLD from 6406 returning 7
Im 6408 returning 7
Im 6407 returning 7
Im 6409 returning 7
Im 6405. Caught a SIGCHLD from 6409 returning 7
Im 6410 returning 7
Im 6405. Caught a SIGCHLD from 6408 returning 7
Im 6405. Caught a SIGCHLD from 6410 returning 7
Ending handler of 6410
Ending handler of 6408
Ending handler of 6409
Ending handler of 6406
$