2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>sigtrap - Perl pragma to enable simple signal handling
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> sigtrap - Perl pragma to enable simple signal handling
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
25 <li><a href=
"#options">OPTIONS
</a></li>
28 <li><a href=
"#signal_handlers">SIGNAL HANDLERS
</a></li>
29 <li><a href=
"#signal_lists">SIGNAL LISTS
</a></li>
30 <li><a href=
"#other">OTHER
</a></li>
33 <li><a href=
"#examples">EXAMPLES
</a></li>
40 <h1><a name=
"name">NAME
</a></h1>
41 <p>sigtrap - Perl pragma to enable simple signal handling
</p>
45 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
48 use sigtrap qw(stack-trace old-interface-signals); # equivalent
49 use sigtrap qw(BUS SEGV PIPE ABRT);
50 use sigtrap qw(die INT QUIT);
51 use sigtrap qw(die normal-signals);
52 use sigtrap qw(die untrapped normal-signals);
53 use sigtrap qw(die untrapped normal-signals
54 stack-trace any error-signals);
55 use sigtrap 'handler' =
> \
&my_handler, 'normal-signals';
56 use sigtrap qw(handler my_handler normal-signals
57 stack-trace error-signals);
</pre>
61 <h1><a name=
"description">DESCRIPTION
</a></h1>
62 <p>The
<strong>sigtrap
</strong> pragma is a simple interface to installing signal
63 handlers. You can have it install one of two handlers supplied by
64 <strong>sigtrap
</strong> itself (one which provides a Perl stack trace and one which
65 simply
<a href=
"#item_die"><code>die()
</code></a>s), or alternately you can supply your own handler for it
66 to install. It can be told only to install a handler for signals which
67 are either untrapped or ignored. It has a couple of lists of signals to
68 trap, plus you can supply your own list of signals.
</p>
69 <p>The arguments passed to the
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use
</code></a> statement which invokes
<strong>sigtrap
</strong>
70 are processed in order. When a signal name or the name of one of
71 <strong>sigtrap
</strong>'s signal lists is encountered a handler is immediately
72 installed, when an option is encountered it affects subsequently
73 installed handlers.
</p>
77 <h1><a name=
"options">OPTIONS
</a></h1>
80 <h2><a name=
"signal_handlers">SIGNAL HANDLERS
</a></h2>
81 <p>These options affect which handler will be used for subsequently
82 installed signals.
</p>
84 <dt><strong><a name=
"item_stack_2dtrace"><strong>stack-trace
</strong></a></strong>
87 <p>The handler used for subsequently installed signals outputs a Perl stack
88 trace to STDERR and then tries to dump core. This is the default signal
92 <dt><strong><a name=
"item_die"><strong>die
</strong></a></strong>
95 <p>The handler used for subsequently installed signals calls
<a href=
"#item_die"><code>die
</code></a>
96 (actually
<code>croak
</code>) with a message indicating which signal was caught.
</p>
99 <dt><strong><a name=
"item_handler_your_2dhandler"><strong>handler
</strong> <em>your-handler
</em></a></strong>
102 <p><em>your-handler
</em> will be used as the handler for subsequently installed
103 signals.
<em>your-handler
</em> can be any value which is valid as an
104 assignment to an element of
<a href=
"file://C|\msysgit\mingw\html/pod/perlvar.html#item__sig"><code>%SIG
</code></a>.
</p>
110 <h2><a name=
"signal_lists">SIGNAL LISTS
</a></h2>
111 <p><strong>sigtrap
</strong> has a few built-in lists of signals to trap. They are:
</p>
113 <dt><strong><a name=
"item_normal_2dsignals"><strong>normal-signals
</strong></a></strong>
116 <p>These are the signals which a program might normally expect to encounter
117 and which by default cause it to terminate. They are HUP, INT, PIPE and
121 <dt><strong><a name=
"item_error_2dsignals"><strong>error-signals
</strong></a></strong>
124 <p>These signals usually indicate a serious problem with the Perl
125 interpreter or with your script. They are ABRT, BUS, EMT, FPE, ILL,
126 QUIT, SEGV, SYS and TRAP.
</p>
129 <dt><strong><a name=
"item_old_2dinterface_2dsignals"><strong>old-interface-signals
</strong></a></strong>
132 <p>These are the signals which were trapped by default by the old
133 <strong>sigtrap
</strong> interface, they are ABRT, BUS, EMT, FPE, ILL, PIPE, QUIT,
134 SEGV, SYS, TERM, and TRAP. If no signals or signals lists are passed to
135 <strong>sigtrap
</strong>, this list is used.
</p>
139 <p>For each of these three lists, the collection of signals set to be
140 trapped is checked before trapping; if your architecture does not
141 implement a particular signal, it will not be trapped but rather
142 silently ignored.
</p>
145 <h2><a name=
"other">OTHER
</a></h2>
147 <dt><strong><a name=
"item_untrapped"><strong>untrapped
</strong></a></strong>
150 <p>This token tells
<strong>sigtrap
</strong> to install handlers only for subsequently
151 listed signals which aren't already trapped or ignored.
</p>
154 <dt><strong><a name=
"item_any"><strong>any
</strong></a></strong>
157 <p>This token tells
<strong>sigtrap
</strong> to install handlers for all subsequently
158 listed signals. This is the default behavior.
</p>
161 <dt><strong><a name=
"item_signal"><em>signal
</em></a></strong>
164 <p>Any argument which looks like a signal name (that is,
165 <code>/^[A-Z][A-Z0-
9]*$/
</code>) indicates that
<strong>sigtrap
</strong> should install a
166 handler for that name.
</p>
169 <dt><strong><a name=
"item_number"><em>number
</em></a></strong>
172 <p>Require that at least version
<em>number
</em> of
<strong>sigtrap
</strong> is being used.
</p>
179 <h1><a name=
"examples">EXAMPLES
</a></h1>
180 <p>Provide a stack trace for the old-interface-signals:
</p>
185 use sigtrap qw(stack-trace old-interface-signals);
</pre>
186 <p>Provide a stack trace on the
4 listed signals only:
</p>
188 use sigtrap qw(BUS SEGV PIPE ABRT);
</pre>
189 <p>Die on INT or QUIT:
</p>
191 use sigtrap qw(die INT QUIT);
</pre>
192 <p>Die on HUP, INT, PIPE or TERM:
</p>
194 use sigtrap qw(die normal-signals);
</pre>
195 <p>Die on HUP, INT, PIPE or TERM, except don't change the behavior for
196 signals which are already trapped or ignored:
</p>
198 use sigtrap qw(die untrapped normal-signals);
</pre>
199 <p>Die on receipt one of an of the
<strong>normal-signals
</strong> which is currently
200 <strong>untrapped
</strong>, provide a stack trace on receipt of
<strong>any
</strong> of the
201 <strong>error-signals
</strong>:
</p>
203 use sigtrap qw(die untrapped normal-signals
204 stack-trace any error-signals);
</pre>
205 <p>Install
<code>my_handler()
</code> as the handler for the
<strong>normal-signals
</strong>:
</p>
207 use sigtrap 'handler', \
&my_handler, 'normal-signals';
</pre>
208 <p>Install
<code>my_handler()
</code> as the handler for the normal-signals, provide a
209 Perl stack trace on receipt of one of the error-signals:
</p>
211 use sigtrap qw(handler my_handler normal-signals
212 stack-trace error-signals);
</pre>
213 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
214 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
215 <big><strong><span class=
"block"> sigtrap - Perl pragma to enable simple signal handling
</span></strong></big>