31.18. use sigtrapuse sigtrap; use sigtrap qw(stack-trace old-interface-signals); # same thing use sigtrap qw(BUS SEGV PIPE ABRT); use sigtrap qw(die INT QUIT); use sigtrap qw(die normal-signals); use sigtrap qw(die untrapped normal-signals); use sigtrap qw(die untrapped normal-signals stack-trace any error-signals); use sigtrap 'handler' => \&my_handler, 'normal-signals'; use sigtrap qw(handler my_handler normal-signals stack-trace error-signals); The sigtrap pragma installs some simple signal handlers on your behalf so that you don't have to worry about them. This is useful in situations where an untrapped signal would cause your program to misbehave, like when you have END {} blocks, object destructors, or other at-exit processing that needs to be run no matter how your program happens to terminate. The sigtrap pragma provides two simple signal handlers for your use. One provides a Perl stack trace, and the other throws an ordinary exception via die. Alternately, you can supply your own handler for the pragma to install. You may specify predefined sets of signals to trap; you can also supply your own explicit list of signals. The pragma can optionally install handlers for only those signals that have not otherwise been handled. Arguments passed to use sigtrap are processed in order. When a user-supplied signal name or the name of one of sigtrap's predefined signal lists is encountered, a handler is immediately installed. When an option is encountered, this affects only those handlers installed later in processing the argument list. 31.18.1. Signal HandlersThese options affect which handler will be used for signals installed later:
31.18.2. Predefined Signal ListsThe sigtrap pragma has a few built-in lists of signals to trap:
If your platform does not implement a particular signal named in the predefined lists, that signal name will be silently ignored. (The signal itself can't be ignored, because it doesn't exist.) 31.18.3. Other Arguments to sigtrap
31.18.4. Examples of sigtrapProvide a stack trace for the old interface signals: Same thing, but more explicitly:use sigtrap; Provide a stack trace only on the four listed signals:use sigtrap qw(stack-trace old-interface-signals); Die on an INT or a QUIT signal:use sigtrap qw(BUS SEGV PIPE ABRT); Die on any of HUP, INT, PIPE, or TERM:use sigtrap qw(die INT QUIT); Die on HUP, INT, PIPE, or TERM--except don't change the behavior for signals that have already been trapped or ignored elsewhere in the program:use sigtrap qw(die normal-signals); Die on receipt of any currently untrapped normal-signals; additionally, provide a stack backtrace on receipt of any of the error-signals:use sigtrap qw(die untrapped normal-signals); Install the routine my_handler as the handler for the normal-signals:use sigtrap qw(die untrapped normal-signals stack-trace any error-signals); Install my_handler as the handler for the normal-signals; provide a Perl stack backtrace on receipt of any of the error-signals:use sigtrap 'handler' => \&my_handler, 'normal-signals'; use sigtrap qw(handler my_handler normal-signals stack-trace error-signals); Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|