[comp.lang.perl] Signal handling...

clewis@eci386.uucp (Chris Lewis) (03/22/90)

I want to be able to set signals in Perl for SIGINT/SIGQUIT/SIGTERM etc.
analogously to the traditional C:

	if (signal(SIGINT, SIG_IGN) == SIG_DFL)
	    signal(SIGINT, &myhandler);

Above means: if SIGINT is set to default behaviour, assign it to my handler, 
otherwise ignore INT's altogether.  Unfortunately $SIG{'INT'} isn't 
initialized to anything at perl start-up time (as per the manual), so I 
can't tell whether it's SIG_DFL or SIG_IGN (eg: I can't tell whether the
command is foreground or background respectively).  My code is currently
saying:

    if (-t) {
	... set INT/TERM/QUIT signals to my handler ...
    }

But this is usually wrong.....  Any ideas?
-- 
Chris Lewis, Elegant Communications Inc, {uunet!attcan,utzoo}!lsuc!eci386!clewis
Ferret mailing list: eci386!ferret-list, psroff mailing list: eci386!psroff-list

tchrist@convex.COM (Tom Christiansen) (03/22/90)

In article <1990Mar21.173423.7281@eci386.uucp> clewis@eci386 (Chris Lewis) writes:
>I want to be able to set signals in Perl for SIGINT/SIGQUIT/SIGTERM etc.
>analogously to the traditional C:
>
>	if (signal(SIGINT, SIG_IGN) == SIG_DFL)
>	    signal(SIGINT, &myhandler);

Isn't this for people who don't have shells with job control and
whose background jobs still get keyboard interrupts?

--tom
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"

chip@tct.uucp (Chip Salzenberg) (03/23/90)

Chris Lewis writes:
>>	if (signal(SIGINT, SIG_IGN) == SIG_DFL)
>>	    signal(SIGINT, &myhandler);

According to tchrist@convex.COM (Tom Christiansen):
>Isn't this for people who don't have shells with job control and
>whose background jobs still get keyboard interrupts?

This idiom is for people who don't have kernels with signal masks.
Job control and signal masks are separate features.  With a signal
mask, you can set to catch a signal and still be protected from that
signal.  Without a signal mask, setting up the catcher opens you up to
the signal you're trying to catch.

Which reminds me...  does Perl attempt signal mask manipulation?
I suppose syscall() and vec() can handle it...
-- 
Chip Salzenberg at ComDev/TCT   <chip%tct@ateng.com>, <uunet!ateng!tct!chip>
          "The Usenet, in a very real sense, does not exist."

clewis@eci386.uucp (Chris Lewis) (03/27/90)

In article <100773@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
| In article <1990Mar21.173423.7281@eci386.uucp> clewis@eci386 (Chris Lewis) writes:
| >I want to be able to set signals in Perl for SIGINT/SIGQUIT/SIGTERM etc.
| >analogously to the traditional C:
| >
| >	if (signal(SIGINT, SIG_IGN) == SIG_DFL)
| >	    signal(SIGINT, &myhandler);
| 
| Isn't this for people who don't have shells with job control and
| whose background jobs still get keyboard interrupts?

No.  This is for people who want SIGINT to be ignored in the background (as 
is normal), but respected with a non-default handler in the foreground 
allowing the program to catch it and use the handler to clean things up.
Lots of standard UNIX utilities need to catch SIGINT in this fashion.
-- 
Chris Lewis, Elegant Communications Inc, {uunet!attcan,utzoo}!lsuc!eci386!clewis
Ferret mailing list: eci386!ferret-list, psroff mailing list: eci386!psroff-list