satchboost has asked for the wisdom of the Perl Monks concerning the following question:

I've got a complex PERL application running and it has a CLI. Part of this CLI is that you can hit CTRL-C to stop the current process and return to the command-line. Now, I'm trapping SIGINT by doing a
my $abort = 0; my $old_sig_int = $SIG{'INT'} || ''; $SIG{'INT'} = sub { $abort = 1; };
and handling $abort later in the code. Now, on occasion, one of my users has noticed that if he hits CTRL-C, he actually causes a SIGTERM in the select() call I use to act as my heartbeat timer. Why would this happen? I've read through all the books I have and cannot find why this would be.

The big problem with this is that Perl 5.005_2 doesn't remove the job from Solaris 2.6. As the application is a resource hog, this causes the server to come to a slow and grinding halt.

1) Is trapping $SIG{'TERM'} going to be useful? 2) Why is select() throwing a SIGTERM in the first place? 3) Why is it just one account and not another? I cannot reproduce it from my account, but can from his at will.

(Yes, I know I should be using Sockets, but I haven't upgraded the application to do so. Perl5.6 isn't coming for a while, so I have to make do with what I've got.)

Replies are listed 'Best First'.
Re: Handling SIGTERM
by AgentM (Curate) on Mar 08, 2001 at 09:26 UTC
    About the SIGTERM: Ask the guy which shell he uses- something obscure or outdated? select is a kernel call. If it generates that signal, it's the kernels fault (this is not POSIX behavior to generate SIGTERM) but the shell might throw a wrench in somewhere. This interrupted kernel call should not generate a signal, halting the program should- are you sure you're looking at the right place? Reduce the program to minimum size to reproduce the problem. Consider complaining to Sun or the maker of the shell. For far easier and more dependable way to deal with CTRL-C, use Curses instead of catching the signal. If you set it up correctly, signal use won't even be warranted, which is the better of the cases in Perl. Good luck!
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.