]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/signal.2
strip trailing white space
[thirdparty/man-pages.git] / man2 / signal.2
CommitLineData
fea681da 1.\" Copyright (c) 2000 Andries Brouwer <aeb@cwi.nl>
544195a1 2.\" and Copyright (c) 2007 Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
3.\" based on work by Rik Faith <faith@cs.unc.edu>
4.\" and Mike Battersby <mike@starbug.apana.org.au>.
5.\"
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
9.\"
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
c13182ef 14.\"
fea681da
MK
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
c13182ef 22.\"
fea681da
MK
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
25.\"
c13182ef
MK
26.\" Modified 2004-11-19, mtk:
27.\" added pointer to sigaction.2 for details of ignoring SIGCHLD
218d23e5
MK
28.\" 2007-06-03, mtk: strengthened portability warning, and rerote
29.\" various sections.
197362df 30.\"
bc0d5df3 31.TH SIGNAL 2 2007-06-03 "Linux" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33signal \- ANSI C signal handling
34.SH SYNOPSIS
35.B #include <signal.h>
36.sp
37.B typedef void (*sighandler_t)(int);
38.sp
39.BI "sighandler_t signal(int " signum ", sighandler_t " handler );
40.SH DESCRIPTION
988db661 41The behavior of
bc0d5df3
MK
42.BR signal ()
43varies across Unix versions,
44and has also varied historically across different versions of Linux.
45\fBAvoid its use\fP: use
46.BR sigaction (2)
47instead.
48See \fIPortability\fP below.
49
fea681da 50.BR signal ()
218d23e5
MK
51sets the disposition of the signal
52.IR signum
53to
54.IR handler ,
55which is either
56.BR SIG_IGN ,
57.BR SIG_DFL ,
58or the address of a programmer-defined function (a "signal handler"),
fea681da 59
218d23e5 60If the signal
fea681da 61.I signum
218d23e5
MK
62is delivered to the process, then one of the following happens:
63.TP 3
64*
65If the disposition is set to
fea681da
MK
66.BR SIG_IGN ,
67then the signal is ignored.
218d23e5
MK
68.TP
69*
70If the disposition is set to
fea681da 71.BR SIG_DFL ,
99d2b7a2 72then the default action associated with the signal (see
fea681da
MK
73.BR signal (7))
74occurs.
218d23e5
MK
75.TP
76*
77If the disposition is set to a function,
78then first either the disposition is reset to
79.BR SIG_DFL ,
80or the signal is blocked (see \fIPortability\fP below), and then
f9212394 81.I handler
fea681da
MK
82is called with argument
83.IR signum .
eb1af896 84If invocation of the handler caused the signal to be blocked,
218d23e5
MK
85then the signal is unblocked upon return from the handler.
86.PP
fea681da
MK
87The signals
88.B SIGKILL
89and
90.B SIGSTOP
91cannot be caught or ignored.
fea681da 92.SH "RETURN VALUE"
fea681da 93.BR signal ()
bc0d5df3 94returns the previous value of the signal handler, or
fea681da
MK
95.B SIG_ERR
96on error.
218d23e5
MK
97.SH ERRORS
98.TP
99.B EINVAL
100.I signum
101is invalid.
2dd578fd
MK
102.SH "CONFORMING TO"
103C89, C99, POSIX.1-2001.
fea681da 104.SH NOTES
988db661 105The effects of
218d23e5
MK
106.BR signal ()
107in a multi-threaded process are unspecified.
fea681da 108.PP
d9bfdb9c 109According to POSIX, the behavior of a process is undefined after it
fea681da
MK
110ignores a
111.BR SIGFPE ,
112.BR SIGILL ,
113or
114.B SIGSEGV
bc0d5df3 115signal that was not generated by
fea681da
MK
116.BR kill (2)
117or the
bc0d5df3 118.BR raise (3).
fea681da
MK
119Integer division by zero has undefined result.
120On some architectures it will generate a
121.B SIGFPE
122signal.
123(Also dividing the most negative integer by \-1 may generate
124.BR SIGFPE .)
125Ignoring this signal might lead to an endless loop.
126.PP
197362df
MK
127See
128.BR sigaction (2)
129for details on what happens when
fea681da
MK
130.B SIGCHLD
131is set to
132.BR SIG_IGN .
fea681da 133.PP
7f82d75e
MK
134See
135.BR signal (7)
988db661 136for a list of the async-signal-safe functions that can be
7f82d75e
MK
137safely called inside from inside a signal handler.
138.PP
fea681da
MK
139The use of
140.B sighandler_t
141is a GNU extension.
142Various versions of libc predefine this type; libc4 and libc5 define
143.IR SignalHandler ,
144glibc defines
145.I sig_t
146and, when
147.B _GNU_SOURCE
148is defined, also
149.IR sighandler_t .
8c87824d
MK
150.SS Portability
151The original Unix
152.BR signal ()
8bd58774
MK
153would reset the handler to
154.BR SIG_DFL ,
155and System V
8c87824d
MK
156(and the Linux kernel and libc4,5) does the same.
157On the other hand, BSD does not reset the handler, but blocks
158new instances of this signal from occurring during a call of the handler.
d9bfdb9c 159The glibc2 library follows the BSD behavior.
8c87824d
MK
160
161If one on a libc5 system includes
c84371c6 162.I <bsd/signal.h>
8c87824d 163instead of
c84371c6 164.I <signal.h>
8c87824d
MK
165then
166.BR signal ()
167is redefined as
bc0d5df3
MK
168.BR __bsd_signal ()
169and
170.BR signal ()
171has the BSD semantics.
8c87824d
MK
172This is not recommended.
173
174If one on a glibc2 system defines a feature test
175macro such as
176.B _XOPEN_SOURCE
177or uses a separate
bc0d5df3 178.BR sysv_signal (3)
d9bfdb9c 179function, one obtains classical behavior.
8c87824d 180This is not recommended.
fea681da
MK
181.SH "SEE ALSO"
182.BR kill (1),
183.BR alarm (2),
184.BR kill (2),
fea681da
MK
185.BR pause (2),
186.BR sigaction (2),
479377fb
MK
187.BR sigpending (2),
188.BR sigprocmask (2),
84b13f1e 189.BR sigqueue (2),
479377fb 190.BR sigsuspend (2),
d6d70cf9 191.BR bsd_signal (3),
84b13f1e 192.BR killpg (3),
fea681da 193.BR raise (3),
bc0d5df3 194.BR siginterrupt (3),
fea681da 195.BR sigsetops (3),
30ecea55 196.BR sigvec (3),
d6d70cf9 197.BR sysv_signal (3),
a8e7c990 198.BR feature_test_macros (7),
fea681da 199.BR signal (7)