1sigtrap(3pm)           Perl Programmers Reference Guide           sigtrap(3pm)
2
3
4

NAME

6       sigtrap - Perl pragma to enable simple signal handling
7

SYNOPSIS

9           use sigtrap;
10           use sigtrap qw(stack-trace old-interface-signals);  # equivalent
11           use sigtrap qw(BUS SEGV PIPE ABRT);
12           use sigtrap qw(die INT QUIT);
13           use sigtrap qw(die normal-signals);
14           use sigtrap qw(die untrapped normal-signals);
15           use sigtrap qw(die untrapped normal-signals
16                           stack-trace any error-signals);
17           use sigtrap 'handler' => \&my_handler, 'normal-signals';
18           use sigtrap qw(handler my_handler normal-signals
19                           stack-trace error-signals);
20

DESCRIPTION

22       The sigtrap pragma is a simple interface to installing signal handlers.
23       You can have it install one of two handlers supplied by sigtrap itself
24       (one which provides a Perl stack trace and one which simply "die()"s),
25       or alternately you can supply your own handler for it to install.  It
26       can be told only to install a handler for signals which are either
27       untrapped or ignored.  It has a couple of lists of signals to trap,
28       plus you can supply your own list of signals.
29
30       The arguments passed to the "use" statement which invokes sigtrap are
31       processed in order.  When a signal name or the name of one of sigtrap's
32       signal lists is encountered a handler is immediately installed, when an
33       option is encountered it affects subsequently installed handlers.
34

OPTIONS

36   SIGNAL HANDLERS
37       These options affect which handler will be used for subsequently
38       installed signals.
39
40       stack-trace
41           The handler used for subsequently installed signals outputs a Perl
42           stack trace to STDERR and then tries to dump core.  This is the
43           default signal handler.
44
45       die The handler used for subsequently installed signals calls "die"
46           (actually "croak") with a message indicating which signal was
47           caught.
48
49       handler your-handler
50           your-handler will be used as the handler for subsequently installed
51           signals.  your-handler can be any value which is valid as an
52           assignment to an element of %SIG. See perlvar for examples of
53           handler functions.
54
55   SIGNAL LISTS
56       sigtrap has a few built-in lists of signals to trap.  They are:
57
58       normal-signals
59           These are the signals which a program might normally expect to
60           encounter and which by default cause it to terminate.  They are
61           HUP, INT, PIPE and TERM.
62
63       error-signals
64           These signals usually indicate a serious problem with the Perl
65           interpreter or with your script.  They are ABRT, BUS, EMT, FPE,
66           ILL, QUIT, SEGV, SYS and TRAP.
67
68       old-interface-signals
69           These are the signals which were trapped by default by the old
70           sigtrap interface, they are ABRT, BUS, EMT, FPE, ILL, PIPE, QUIT,
71           SEGV, SYS, TERM, and TRAP.  If no signals or signals lists are
72           passed to sigtrap, this list is used.
73
74       For each of these three lists, the collection of signals set to be
75       trapped is checked before trapping; if your architecture does not
76       implement a particular signal, it will not be trapped but rather
77       silently ignored.
78
79   OTHER
80       untrapped
81           This token tells sigtrap to install handlers only for subsequently
82           listed signals which aren't already trapped or ignored.
83
84       any This token tells sigtrap to install handlers for all subsequently
85           listed signals.  This is the default behavior.
86
87       signal
88           Any argument which looks like a signal name (that is,
89           "/^[A-Z][A-Z0-9]*$/") indicates that sigtrap should install a
90           handler for that name.
91
92       number
93           Require that at least version number of sigtrap is being used.
94

EXAMPLES

96       Provide a stack trace for the old-interface-signals:
97
98           use sigtrap;
99
100       Ditto:
101
102           use sigtrap qw(stack-trace old-interface-signals);
103
104       Provide a stack trace on the 4 listed signals only:
105
106           use sigtrap qw(BUS SEGV PIPE ABRT);
107
108       Die on INT or QUIT:
109
110           use sigtrap qw(die INT QUIT);
111
112       Die on HUP, INT, PIPE or TERM:
113
114           use sigtrap qw(die normal-signals);
115
116       Die on HUP, INT, PIPE or TERM, except don't change the behavior for
117       signals which are already trapped or ignored:
118
119           use sigtrap qw(die untrapped normal-signals);
120
121       Die on receipt one of an of the normal-signals which is currently
122       untrapped, provide a stack trace on receipt of any of the error-
123       signals:
124
125           use sigtrap qw(die untrapped normal-signals
126                           stack-trace any error-signals);
127
128       Install my_handler() as the handler for the normal-signals:
129
130           use sigtrap 'handler', \&my_handler, 'normal-signals';
131
132       Install my_handler() as the handler for the normal-signals, provide a
133       Perl stack trace on receipt of one of the error-signals:
134
135           use sigtrap qw(handler my_handler normal-signals
136                           stack-trace error-signals);
137
138
139
140perl v5.16.3                      2013-03-04                      sigtrap(3pm)
Impressum