in reply to How "safe" is die() in %SIG?

Prior to 5.8, it was never safe to call die from within a real signal handler. ($SIG{__WARN__} and $SIG{__DIE__} aren't real signal handlers as such, though calling die from within them can cause some interesting things to happen as well) If you have safe signals enabled for 5.8 (and it may be the default these days, I really don't remember) then it will be safe.

Replies are listed 'Best First'.
Re: Re: How "safe" is die() in %SIG?
by slagel (Novice) on May 19, 2003 at 20:30 UTC
    Thanks. I was referring to calling die() in a SIG{INT}... I tried it in 5.6, and as expected, sometimes it works as advertised, sometimes it causes a core dump, and sometimes it just "goes away". I guess it's really time to go to 5.8.
      Calling die() inside a $SIG{INT} handler is definitely asking for trouble. Perl can and will segfault, as you've found. die allocates memory, which is a no-no inside an interrupt handler, hence the problem. 5.8 takes care of this, though there are downsides to that related to alarm and blocking system calls.