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 (2);
}
__END__
####
C:\>perl \dev\loose\perlfunc.exit.pl
calling system
called sleeping 1 at \dev\loose\perlfunc.exit.pl line 4.
called sleeping 2 at \dev\loose\perlfunc.exit.pl line 4.
called sleeping 3 at \dev\loose\perlfunc.exit.pl line 4.
called sleeping 4 at \dev\loose\perlfunc.exit.pl line 4.
called sleeping 5 at \dev\loose\perlfunc.exit.pl line 4.
Terminating on signal SIGINT(2)
C:\>called Program interrupted ..
C:\>
####
user@host:~$ perl perlfunc.exit.pl
calling system
called sleeping 1 at perlfunc.exit.pl line 4.
called sleeping 2 at perlfunc.exit.pl line 4.
called sleeping 3 at perlfunc.exit.pl line 4.
called sleeping 4 at perlfunc.exit.pl line 4.
called Program interrupted ..
exit_val 2 at perlfunc.exit.pl line 14.
user@host:~$
user@host:~$