Here is the full code I used (I have tried also the fork-exec method) but no luck:
### Calling.pl
#!/usr/local/bin/perl -w
#eval { system ("./called.pl"); };
#$exit_value = $?;
#$exit_value = system ("./called.pl");
if ($pid2 = fork) {
# parent catches INT
print "IN PAR\n";
local $SIG{INT} = sub { print "In parent ...wait\n" };
waitpid ($pid2, 0);
}
else {
die "cannot fork: $!" unless defined $pid2;
eval { exec ("./called.pl"); };
}
print "\nE-at = $@\n";
print "\nE-! = $!\n";
print "\nE = $exit_value\n";
$exit_value = $exit_value >> 8; # Get the higher byte which has the real exit value
print "\nE1 = $exit_value\n";
### called.pl
#!/usr/local/bin/perl -w
if (@ARGV) {
$SIG{INT} = \&exit_gracefully;
for(1..10){
warn "called sleeping $_";
select undef, undef, undef, 0.5;
}
exit 1;
} else {
warn "calling system\n";
system ( $^X, __FILE__ , 'called');
$exit_val = $? >> 8;
warn "\n exit_val $exit_val";
}
sub exit_gracefully
{
$SIG{INT} = \&exit_gracefully;
print "@ARGV Program interrupted .. \n";
exit (3);
}
###Output.txt
IN PAR
calling system
called sleeping 1 at ./called.pl line 6.
called sleeping 2 at ./called.pl line 6.
called sleeping 3 at ./called.pl line 6.
called sleeping 4 at ./called.pl line 6.
^Ccalled Program interrupted ..
In parent ...wait
exit_val 3 at ./called.pl line 16.
E-at =
E-! = Interrupted system call
Use of uninitialized value in concatenation (.) or string at ./calling.pl line 22.
E =
Use of uninitialized value in right bitshift (>>) at ./calling.pl line 24.
E1 = 0
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.