On Thu, 26 Feb 2004, Eric Wilhelm wrote:
> So, using local() inside of your start_interpreter() block should take care of
> it. The following should demonstrate it in it's barest form:
>
> # this one dies:
> sub reap {die "reaped"};
> {
> local($SIG{CHLD}) = \&reap;
> system("ls");
> }
>
> # doesn't die:
> sub reap {die "reaped"};
> {
> local($SIG{CHLD}) = \&reap;
> }
> system("ls");
It's taken me a while to work with this. However, while this works for
a bare "system" call, it doesn't work for the IPC::Open? calls.
For example:
use IPC::Open2;
use IO::File;
my $Oin = new IO::File;
my $Oout= new IO::File;
sub reap {die "reaped"};
# doesn't die:
{
local $SIG{CHLD} = \&reap;
open2( $Oout, $Oin, "/bin/sh" );
}
print $Oin "echo 'boo1' ; sleep 1; exit\n";
print while <$Oout>;
# dies
{
$SIG{CHLD} = \&reap;
open2( $Oout, $Oin, "/bin/sh" );
}
print $Oin "echo 'boo2' ; sleep 1; exit\n";
print while <$Oout>;
# dies
{
local $SIG{CHLD} = \&reap;
open2( $Oout, $Oin, "/bin/sh" );
print $Oin "echo 'boo3' ; sleep 1; exit\n";
print while <$Oout>;
}
Do you have any idea why IPC::Open2 is different from fork?
Andy