1 .\" Copyright (c) 2000 Andries Brouwer <aeb@cwi.nl>
2 .\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" and Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
4 .\" <mtk.manpages@gmail.com>
5 .\" based on work by Rik Faith <faith@cs.unc.edu>
6 .\" and Mike Battersby <mike@starbug.apana.org.au>.
8 .\" Permission is granted to make and distribute verbatim copies of this
9 .\" manual provided the copyright notice and this permission notice are
10 .\" preserved on all copies.
12 .\" Permission is granted to copy and distribute modified versions of this
13 .\" manual under the conditions for verbatim copying, provided that the
14 .\" entire resulting derived work is distributed under the terms of a
15 .\" permission notice identical to this one.
17 .\" Since the Linux kernel and libraries are constantly changing, this
18 .\" manual page may be incorrect or out-of-date. The author(s) assume no
19 .\" responsibility for errors or omissions, or for damages resulting from
20 .\" the use of the information contained herein. The author(s) may not
21 .\" have taken the same level of care in the production of this manual,
22 .\" which is licensed free of charge, as they might when working
25 .\" Formatted or processed versions of this manual, if unaccompanied by
26 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Modified 2004-11-19, mtk:
29 .\" added pointer to sigaction.2 for details of ignoring SIGCHLD
30 .\" 2007-06-03, mtk: strengthened portability warning, and rewrote
32 .\" 2008-07-11, mtk: rewrote and expanded portability discussion.
34 .TH SIGNAL 2 2008-07-11 "Linux" "Linux Programmer's Manual"
36 signal \- ANSI C signal handling
38 .B #include <signal.h>
40 .B typedef void (*sighandler_t)(int);
42 .BI "sighandler_t signal(int " signum ", sighandler_t " handler );
46 varies across UNIX versions,
47 and has also varied historically across different versions of Linux.
48 \fBAvoid its use\fP: use
51 See \fIPortability\fP below.
54 sets the disposition of the signal
61 or the address of a programmer-defined function (a "signal handler").
65 is delivered to the process, then one of the following happens:
68 If the disposition is set to
70 then the signal is ignored.
73 If the disposition is set to
75 then the default action associated with the signal (see
80 If the disposition is set to a function,
81 then first either the disposition is reset to
83 or the signal is blocked (see \fIPortability\fP below), and then
85 is called with argument
87 If invocation of the handler caused the signal to be blocked,
88 then the signal is unblocked upon return from the handler.
94 cannot be caught or ignored.
97 returns the previous value of the signal handler, or
106 C89, C99, POSIX.1-2001.
110 in a multithreaded process are unspecified.
112 According to POSIX, the behavior of a process is undefined after it
118 signal that was not generated by
122 Integer division by zero has undefined result.
123 On some architectures it will generate a
126 (Also dividing the most negative integer by \-1 may generate
128 Ignoring this signal might lead to an endless loop.
132 for details on what happens when
139 for a list of the async-signal-safe functions that can be
140 safely called from inside a signal handler.
145 Various versions of libc predefine this type; libc4 and libc5 define
153 Without use of such a type, the declaration of
155 is the somewhat harder to read:
159 .BI "void ( *" signal "(int " signum ", void (*" handler ")(int)) ) (int);"
163 The only portable use of
165 is to set a signal's disposition to
169 The semantics when using
171 to establish a signal handler vary across systems
172 (and POSIX.1 explicitly permits this variation);
173 .B do not use it for this purpose.
175 POSIX.1 solved the portability mess by specifying
177 which provides explicit control of the semantics when a
178 signal handler is invoked; use that interface instead of
181 In the original UNIX systems, when a handler that was established using
183 was invoked by the delivery of a signal,
184 the disposition of the signal would be reset to
186 and the system did not block delivery of further instances of the signal.
187 System V also provides these semantics for
189 This was bad because the signal might be delivered again
190 before the handler had a chance to reestablish itself.
191 Furthermore, rapid deliveries of the same signal could
192 result in recursive invocations of the handler.
194 BSD improved on this situation by changing the semantics of
196 (but, unfortunately, silently changed the semantics
197 when establishing a handler with
199 On BSD, when a signal handler is invoked,
200 the signal disposition is not reset,
201 and further instances of the signal are blocked from
202 being delivered while the handler is executing.
204 The situation on Linux is as follows:
208 system call provides System V semantics.
210 By default, in glibc 2 and later, the
212 wrapper function does not invoke the kernel system call.
215 using flags that supply BSD semantics.
216 This default behavior is provided as long as the
218 feature test macro is defined.
222 it is also implicitly defined if one defines
224 and can of course be explicitly defined.
226 On glibc 2 and later, if the
228 feature test macro is not defined, then
230 provides System V semantics.
231 (The default implicit definition of
233 is not provided if one invokes
235 in one of its standard modes
236 .RI ( -std=xxx " or " -ansi )
237 or defines various other feature test macros such as
243 .BR feature_test_macros (7).)
245 .\" System V semantics are also provided if one uses the separate
246 .\" .BR sysv_signal (3)
251 function in Linux libc4 and libc5 provide System V semantics.
252 If one on a libc5 system includes
258 provides BSD semantics.
273 .BR siginterrupt (3),