Subject: | signal handler $SIG{CHLD} is not preserved |
Date: | Sun, 4 Feb 2018 22:23:15 +0800 |
To: | bug-Forks-Super [...] rt.cpan.org |
From: | Gerulf Schnitzler <gerulf [...] myprofitsee.com> |
Forks-Super-0.92
perl v5.24.3
Linux 4.12.12-gentoo #1 SMP x86_64 Intel(R) Core(TM) i7-5500U
cpanm -n --verbose Proc::ProcessTable Forks::Super # running tests did
not finish, without --verbose it would fail.
##################
package Process::Manager;
use strict;
use warnings;
use Exporter qw(import);
use Forks::Super;
our @EXPORT_OK = qw(task_manager);
sub task_manager {
my $worker=shift;
#local $SIG{CHLD}=undef;
my $pid = fork { sub => $worker };
waitall;
return;
}
1;
################
#!/usr/bin/perl
use strict;
use warnings;
use Process::Manager qw(task_manager);
print $SIG{CHLD}, "\n" if defined( $SIG{CHLD} );
task_manager( sub { sleep 1 } );
print $SIG{CHLD}, "\n" if defined( $SIG{CHLD} );
while (1) {
sleep 1;
open my $fh, '-|', "ls" or die 'could not open \'ls\'';
print "open: $!, $?.\n";
my @ignore = <$fh>;
print "read: $!, $?.\n";
close $fh or die "oh my $! $?";
print "close: $!, $?\n";
}
##############
running this, results in the following:
$ ./reference.pl
CODE(0x55f9e3978210)
open: Illegal seek, -1.
read: , -1.
close: , 0
open: Illegal seek, 0.
read: , 0.
close: , 0
open: Illegal seek, 0.
read: , 0.
close: , 0
open: Illegal seek, 0.
read: , 0.
oh my No child processes -1 at ./reference2.pl line X.
############
time it takes to die might vary.
As you can see by the single output of 'CODE(0x55f9e3978210)', the
$SIG{CHLD} handler is not preserved upon returning from the module
Process::Manager. If you uncomment the line '#local $SIG{CHLD}=undef; ',
the program runs as expected.
Besides the pollution of the global namespace and the resulting actions
at a distance, this also means that the same while(1) block can not be
executed at the end of Process::Manager, among other implications.
It would be nice to at least document these gotchas.
Furthermore i noticed a few other things while debugging that are not
worth a bug report.
Two i want to share:
fork { max_proc => 0, ... } gives uninitialized value. -1 fixed that
usage of die "foo" in a forked subroutine does not print 'foo' on the
childs STDERR.
local $SIG{__DIE__} = sub { print STDERR @_ }; in the caller fixed that.
this might also be worth documenting
Regards
--
Gerulf Schnitzler
System Administrator
Toll Free: (866) 668-6510 <tel:%28866%29%20668-6510>
Email: gerulf@myprofitsee.com <mailto:gerulf@myprofitsee.com>
Web: www.MyProfitSee.com <https://www.myprofitsee.com/>
7935 Stone Creek Dr. Suite 120
Chanhassen, MN 55317 USA