This worked for me. Here's the simple driver script:
#!/bin/sh -
# @(#) s1 Demonstrate catching signal in perl, return to shell.
echo
echo " Calling perl script."
./user1
echo
echo " Returned from perl script."
exit 0
and the perl script it calls is:
#!/usr/bin/perl
$SIG{'INT'} = 'Handler';
#some code
print "\n Will wait for you to enter ^C ";
my ($junk) + <>;
#signal handling
sub Handler {
print "\n Caught ^C \n";
exit(0);
}
I moved the hash setting above the print and read. Executed twice, once with a simple RETURN and once with ^C yields:
user-problem/228 % ./s1
Calling perl script.
Will wait for you to enter ^C
Returned from perl script.
user-problem/228 % ./s1
Calling perl script.
Will wait for you to enter ^C
Caught ^C
Returned from perl script.
So in both cases, control returns to the shell. My understanding is that signals are caught by the perl process, but not seen by the shell process, like most things for parent-child processes.
If you replaced the shell process with the perl script, say with exec, then the behavior described by the OP would be seen. I verified that with a separate script.
The Programming Perl 3rd, p 413, advises not doing much in the handler beyond setting a global variable, q.v. So I suppose it's possible that if you had a lot of code in the handler, you might run into trouble; PP suggests that a memory fault could occur, even for print statements.
Do this help or confuse the issue? ... cheers, drl