I experience some weird return values from system()when the child process receives SIGINT from the terminal. To explain, from a Perl script, parent.plI used system()to run another Perl script as a child process, but I also needed to run the child through the shell, so I used the form system 'sh', '-c', .... Thus, the parent of the child process became sh, and the parent process shbecame parent.pl. In addition, in order to avoid the process shreceiving the signal SIGINT, I locked it.
For example parent.pl:
use feature qw(say);
use strict;
use warnings;
for (1..3) {
my $res = system 'sh', '-c', "trap '' INT; child$_.pl";
say "Parent received return value: " . ($res >> 8);
}
where child1.pl:
local $SIG{INT} = "DEFAULT";
sleep 10;
say "Child timed out..";
exit 1;
child2.pl:
local $SIG{INT} = sub { die };
sleep 10;
say "Child timed out..";
exit 1;
and child3.pl:
eval {
local $SIG{INT} = sub { die };
sleep 10;
};
if ( $@ ) {
print $@;
exit 2;
}
say "Child timed out..";
exit 0;
parent.pl ( ) CTRL-C, , :
^CParent received return value: 130
^CDied at ./child2.pl line 7.
Parent received return value: 4
^CDied at ./child3.pl line 8.
Parent received return value: 2
, 130 1 4 2.
, , "DEFAULT" .
: , sh bash ( trap SIGINT INT bash).
. :