| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "sigtrap 3perl" |
| 58 |
.TH sigtrap 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
sigtrap \- Perl pragma to enable simple signal handling |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 11 |
| 68 |
\& use sigtrap; |
| 69 |
\& use sigtrap qw(stack\-trace old\-interface\-signals); # equivalent |
| 70 |
\& use sigtrap qw(BUS SEGV PIPE ABRT); |
| 71 |
\& use sigtrap qw(die INT QUIT); |
| 72 |
\& use sigtrap qw(die normal\-signals); |
| 73 |
\& use sigtrap qw(die untrapped normal\-signals); |
| 74 |
\& use sigtrap qw(die untrapped normal\-signals |
| 75 |
\& stack\-trace any error\-signals); |
| 76 |
\& use sigtrap \*(Aqhandler\*(Aq => \e&my_handler, \*(Aqnormal\-signals\*(Aq; |
| 77 |
\& use sigtrap qw(handler my_handler normal\-signals |
| 78 |
\& stack\-trace error\-signals); |
| 79 |
.Ve |
| 80 |
.SH DESCRIPTION |
| 81 |
.IX Header "DESCRIPTION" |
| 82 |
The \fBsigtrap\fR pragma is a simple interface to installing signal |
| 83 |
handlers. You can have it install one of two handlers supplied by |
| 84 |
\&\fBsigtrap\fR itself (one which provides a Perl stack trace and one which |
| 85 |
simply \f(CWdie()\fRs), or alternately you can supply your own handler for it |
| 86 |
to install. It can be told only to install a handler for signals which |
| 87 |
are either untrapped or ignored. It has three lists of signals to |
| 88 |
trap, plus you can supply your own list of signals. |
| 89 |
.PP |
| 90 |
The arguments passed to the \f(CW\*(C`use\*(C'\fR statement which invokes \fBsigtrap\fR |
| 91 |
are processed in order. When a signal name or the name of one of |
| 92 |
\&\fBsigtrap\fR's signal lists is encountered a handler is immediately |
| 93 |
installed, when an option is encountered it affects subsequently |
| 94 |
installed handlers. |
| 95 |
.SH OPTIONS |
| 96 |
.IX Header "OPTIONS" |
| 97 |
.SS "SIGNAL HANDLERS" |
| 98 |
.IX Subsection "SIGNAL HANDLERS" |
| 99 |
These options affect which handler will be used for subsequently |
| 100 |
installed signals. |
| 101 |
.IP \fBstack-trace\fR 4 |
| 102 |
.IX Item "stack-trace" |
| 103 |
The handler used for subsequently installed signals outputs a Perl stack |
| 104 |
trace to STDERR and then tries to dump core. This is the default signal |
| 105 |
handler. |
| 106 |
.IP \fBdie\fR 4 |
| 107 |
.IX Item "die" |
| 108 |
The handler used for subsequently installed signals calls \f(CW\*(C`die\*(C'\fR |
| 109 |
(actually \f(CW\*(C`croak\*(C'\fR) with a message indicating which signal was caught. |
| 110 |
.IP "\fBhandler\fR \fIyour-handler\fR" 4 |
| 111 |
.IX Item "handler your-handler" |
| 112 |
\&\fIyour-handler\fR will be used as the handler for subsequently installed |
| 113 |
signals. \fIyour-handler\fR can be any value which is valid as an |
| 114 |
assignment to an element of \f(CW%SIG\fR. See perlvar for examples of |
| 115 |
handler functions. |
| 116 |
.SS "SIGNAL LISTS" |
| 117 |
.IX Subsection "SIGNAL LISTS" |
| 118 |
\&\fBsigtrap\fR has a few built-in lists of signals to trap. They are: |
| 119 |
.IP \fBnormal-signals\fR 4 |
| 120 |
.IX Item "normal-signals" |
| 121 |
These are the signals which a program might normally expect to encounter |
| 122 |
and which by default cause it to terminate. They are HUP, INT, PIPE and |
| 123 |
TERM. |
| 124 |
.IP \fBerror-signals\fR 4 |
| 125 |
.IX Item "error-signals" |
| 126 |
These signals usually indicate a serious problem with the Perl |
| 127 |
interpreter or with your script. They are ABRT, BUS, EMT, FPE, ILL, |
| 128 |
QUIT, SEGV, SYS and TRAP. |
| 129 |
.IP \fBold-interface-signals\fR 4 |
| 130 |
.IX Item "old-interface-signals" |
| 131 |
These are the signals which were trapped by default by the old |
| 132 |
\&\fBsigtrap\fR interface, they are ABRT, BUS, EMT, FPE, ILL, PIPE, QUIT, |
| 133 |
SEGV, SYS, TERM, and TRAP. If no signals or signals lists are passed to |
| 134 |
\&\fBsigtrap\fR, this list is used. |
| 135 |
.PP |
| 136 |
For each of these three lists, the collection of signals set to be |
| 137 |
trapped is checked before trapping; if your architecture does not |
| 138 |
implement a particular signal, it will not be trapped but rather |
| 139 |
silently ignored. |
| 140 |
.SS OTHER |
| 141 |
.IX Subsection "OTHER" |
| 142 |
.IP \fBuntrapped\fR 4 |
| 143 |
.IX Item "untrapped" |
| 144 |
This token tells \fBsigtrap\fR to install handlers only for subsequently |
| 145 |
listed signals which aren't already trapped or ignored. |
| 146 |
.IP \fBany\fR 4 |
| 147 |
.IX Item "any" |
| 148 |
This token tells \fBsigtrap\fR to install handlers for all subsequently |
| 149 |
listed signals. This is the default behavior. |
| 150 |
.IP \fIsignal\fR 4 |
| 151 |
.IX Item "signal" |
| 152 |
Any argument which looks like a signal name (that is, |
| 153 |
\&\f(CW\*(C`/^[A\-Z][A\-Z0\-9]*$/\*(C'\fR) indicates that \fBsigtrap\fR should install a |
| 154 |
handler for that name. |
| 155 |
.IP \fInumber\fR 4 |
| 156 |
.IX Item "number" |
| 157 |
Require that at least version \fInumber\fR of \fBsigtrap\fR is being used. |
| 158 |
.SH EXAMPLES |
| 159 |
.IX Header "EXAMPLES" |
| 160 |
Provide a stack trace for the old-interface-signals: |
| 161 |
.PP |
| 162 |
.Vb 1 |
| 163 |
\& use sigtrap; |
| 164 |
.Ve |
| 165 |
.PP |
| 166 |
Ditto: |
| 167 |
.PP |
| 168 |
.Vb 1 |
| 169 |
\& use sigtrap qw(stack\-trace old\-interface\-signals); |
| 170 |
.Ve |
| 171 |
.PP |
| 172 |
Provide a stack trace on the 4 listed signals only: |
| 173 |
.PP |
| 174 |
.Vb 1 |
| 175 |
\& use sigtrap qw(BUS SEGV PIPE ABRT); |
| 176 |
.Ve |
| 177 |
.PP |
| 178 |
Die on INT or QUIT: |
| 179 |
.PP |
| 180 |
.Vb 1 |
| 181 |
\& use sigtrap qw(die INT QUIT); |
| 182 |
.Ve |
| 183 |
.PP |
| 184 |
Die on HUP, INT, PIPE or TERM: |
| 185 |
.PP |
| 186 |
.Vb 1 |
| 187 |
\& use sigtrap qw(die normal\-signals); |
| 188 |
.Ve |
| 189 |
.PP |
| 190 |
Die on HUP, INT, PIPE or TERM, except don't change the behavior for |
| 191 |
signals which are already trapped or ignored: |
| 192 |
.PP |
| 193 |
.Vb 1 |
| 194 |
\& use sigtrap qw(die untrapped normal\-signals); |
| 195 |
.Ve |
| 196 |
.PP |
| 197 |
Die on receipt one of any of the \fBnormal-signals\fR which is currently |
| 198 |
\&\fBuntrapped\fR, provide a stack trace on receipt of \fBany\fR of the |
| 199 |
\&\fBerror-signals\fR: |
| 200 |
.PP |
| 201 |
.Vb 2 |
| 202 |
\& use sigtrap qw(die untrapped normal\-signals |
| 203 |
\& stack\-trace any error\-signals); |
| 204 |
.Ve |
| 205 |
.PP |
| 206 |
Install \fBmy_handler()\fR as the handler for the \fBnormal-signals\fR: |
| 207 |
.PP |
| 208 |
.Vb 1 |
| 209 |
\& use sigtrap \*(Aqhandler\*(Aq, \e&my_handler, \*(Aqnormal\-signals\*(Aq; |
| 210 |
.Ve |
| 211 |
.PP |
| 212 |
Install \fBmy_handler()\fR as the handler for the normal-signals, provide a |
| 213 |
Perl stack trace on receipt of one of the error-signals: |
| 214 |
.PP |
| 215 |
.Vb 2 |
| 216 |
\& use sigtrap qw(handler my_handler normal\-signals |
| 217 |
\& stack\-trace error\-signals); |
| 218 |
.Ve |