Perldoc Search: "%SIG" perl-5.20.1

search official POD

7 PODs, 15 LINEs found.
8 :     Perl uses a simple signal handling model: the %SIG hash contains names or references of user-installed signal handlers. These handlers will be called with an argument which is the name of the signal that triggered it. A signal may be generated intentionally from a particular keyboard sequence like control-C or control-Z, sent to you from another process, or triggered automatically by the kernel when special events transpire, like a child process exiting, your own process running out of stack space, or hitting a process file-size limit.
158 :     Perl 5.8.0 and later avoid these problems by "deferring" signals. That is, when the signal is delivered to the process by the system (to the C code that implements Perl) a flag is set, and the handler returns immediately. Then at strategic "safe" points in the Perl interpreter (e.g. when it is about to execute a new opcode) the flags are checked and the Perl level handler from %SIG is executed. The "deferred" scheme allows much more flexibility in the coding of signal handlers as we know the Perl interpreter is in a safe state, and that we are not in a system library function when the handler is called. However the implementation does differ from previous Perls in the following ways:
166 :         When a signal is delivered (e.g., SIGINT from a control-C) the operating system breaks into IO operations like *read*(2), which is used to implement Perl's readline() function, the "<>" operator. On older Perls the handler was called immediately (and as "read" is not "unsafe", this worked well). With the "deferred" scheme the handler is *not* called immediately, and if Perl is using the system's "stdio" library that library may restart the "read" without returning to Perl to give it a chance to call the %SIG handler. If this happens on your system the solution is to use the ":perlio" layer to do IO--at least on those handles that you want to be able to break into with signals. (The ":perlio" layer checks the signal flags and calls %SIG handlers before resuming IO operation.)
187 :         On systems that supported it, older versions of Perl used the SA_RESTART flag when installing %SIG handlers. This meant that restartable system calls would continue rather than returning when a signal arrived. In order to deliver deferred signals promptly, Perl 5.8.0 and later do *not* use SA_RESTART. Consequently, restartable system calls can fail (with $! set to "EINTR") in places where they previously would have succeeded.
247 :     %SIG    The hash %SIG contains signal handlers for signals. For example:
280 :             Certain internal hooks can be also set using the %SIG hash. The routine indicated by $SIG{__WARN__} is called when a warning message is about to be printed. The warning message is passed as the first argument. The presence of a "__WARN__" hook causes the ordinary printing of warnings to "STDERR" to be suppressed. You can use this to save warnings in a variable, or turn warnings into fatal errors, like this:
939 :             Warning messages are not collected in this variable. You can, however, set up a routine to process warnings by setting $SIG{__WARN__} as described in "%SIG".
783 :      S  PERL_MAGIC_sig            (none)         %SIG hash
784 :      s  PERL_MAGIC_sigelem        vtbl_sigelem   %SIG hash element
1797 :         (W signal) You specified a signal name as a subscript to %SIG that was not recognized. Say "kill -l" in your shell to see the valid signal names on your system.
2612 :         (W signal) The signal handler named in %SIG doesn't, in fact, exist. Perhaps you put it into the wrong package?
705 :         You can arrange for a callback to be run just before the "die" does its deed, by setting the $SIG{__DIE__} hook. The associated handler is called with the error text and can change the error message, if it sees fit, by calling "die" again. See "%SIG" in perlvar for details on setting %SIG entries, and "eval BLOCK" for some examples. Although this feature was to be run only right before your program was to exit, this is not currently so: the $SIG{__DIE__} hook is currently called even inside eval()ed blocks/strings! If one wants the hook to do nothing in such situations, put
4879 :         See perlvar for details on setting %SIG entries and for more examples. See the Carp module for other kinds of warnings using its carp() and cluck() functions.
220 :     Don't count on signals or %SIG for anything.
584 :     When STDERR is tied, its PRINT method will be called to issue warnings and error messages. This feature is temporarily disabled during the call, which means you can use "warn()" inside PRINT without starting a recursive loop. And just like "__WARN__" and "__DIE__" handlers, STDERR's PRINT method may be called to report parser errors, so the caveats mentioned under "%SIG" in perlvar apply.
<< Back to Perldoc Search