in reply to Re: Perl SIG INT handling conundrum.
in thread SOLVED Perl SIG INT handling conundrum.

Thanks for your responses chaps...

Have been working on this since I posted and found the solution....

system("trap '' INT;");

It turns out sshd forces commands by passing them to the user's shell with -c, e.g. /bin/sh -c "forced command".

So it was the remote shell which was catching the Ctrl-C and once the remote ssh client noticed the shell had exited it was also exiting, making it look somewhat like the local side had caught the INT.

The above Perl statement runs a shell command that tells the shell to ignore signal INT so it is available to Perl. I guess when I was running locally from a login shell something in Perl automatically overrides this when you set a custom signal handler.

Not all shells support trap - sh, bash, ksh do but csh and tcsh do not. At least on FreeBSD which is what i'm developing with.

Thanks again for the suggestions and I hope this might be useful to someone sometime!

Replies are listed 'Best First'.
Re^3: Perl SIG INT handling conundrum.
by differenceengine (Novice) on Aug 16, 2011 at 18:57 UTC
    Just as a side note, thinking about it there won't be anything in Perl that overrides signal handling. The important thing here is the order in which the processes receive the signal. Using ssh, the shell receives the signal first and it will only let it "bubble" (to borrow event driven terminology) if it doesn't handle it. Running a Perl script from a shell, the script receives the signal first and if there's no handler passes it down to the shell. Which is as it should be.