]>
Commit | Line | Data |
---|---|---|
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 |
33 | signal \- 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 | 41 | The behavior of |
bc0d5df3 MK |
42 | .BR signal () |
43 | varies across Unix versions, | |
44 | and has also varied historically across different versions of Linux. | |
45 | \fBAvoid its use\fP: use | |
46 | .BR sigaction (2) | |
47 | instead. | |
48 | See \fIPortability\fP below. | |
49 | ||
fea681da | 50 | .BR signal () |
218d23e5 MK |
51 | sets the disposition of the signal |
52 | .IR signum | |
53 | to | |
54 | .IR handler , | |
55 | which is either | |
56 | .BR SIG_IGN , | |
57 | .BR SIG_DFL , | |
58 | or the address of a programmer-defined function (a "signal handler"), | |
fea681da | 59 | |
218d23e5 | 60 | If the signal |
fea681da | 61 | .I signum |
218d23e5 MK |
62 | is delivered to the process, then one of the following happens: |
63 | .TP 3 | |
64 | * | |
65 | If the disposition is set to | |
fea681da MK |
66 | .BR SIG_IGN , |
67 | then the signal is ignored. | |
218d23e5 MK |
68 | .TP |
69 | * | |
70 | If the disposition is set to | |
fea681da | 71 | .BR SIG_DFL , |
99d2b7a2 | 72 | then the default action associated with the signal (see |
fea681da MK |
73 | .BR signal (7)) |
74 | occurs. | |
218d23e5 MK |
75 | .TP |
76 | * | |
77 | If the disposition is set to a function, | |
78 | then first either the disposition is reset to | |
79 | .BR SIG_DFL , | |
80 | or the signal is blocked (see \fIPortability\fP below), and then | |
f9212394 | 81 | .I handler |
fea681da MK |
82 | is called with argument |
83 | .IR signum . | |
eb1af896 | 84 | If invocation of the handler caused the signal to be blocked, |
218d23e5 MK |
85 | then the signal is unblocked upon return from the handler. |
86 | .PP | |
fea681da MK |
87 | The signals |
88 | .B SIGKILL | |
89 | and | |
90 | .B SIGSTOP | |
91 | cannot be caught or ignored. | |
fea681da | 92 | .SH "RETURN VALUE" |
fea681da | 93 | .BR signal () |
bc0d5df3 | 94 | returns the previous value of the signal handler, or |
fea681da MK |
95 | .B SIG_ERR |
96 | on error. | |
218d23e5 MK |
97 | .SH ERRORS |
98 | .TP | |
99 | .B EINVAL | |
100 | .I signum | |
101 | is invalid. | |
2dd578fd MK |
102 | .SH "CONFORMING TO" |
103 | C89, C99, POSIX.1-2001. | |
fea681da | 104 | .SH NOTES |
988db661 | 105 | The effects of |
218d23e5 MK |
106 | .BR signal () |
107 | in a multi-threaded process are unspecified. | |
fea681da | 108 | .PP |
d9bfdb9c | 109 | According to POSIX, the behavior of a process is undefined after it |
fea681da MK |
110 | ignores a |
111 | .BR SIGFPE , | |
112 | .BR SIGILL , | |
113 | or | |
114 | .B SIGSEGV | |
bc0d5df3 | 115 | signal that was not generated by |
fea681da MK |
116 | .BR kill (2) |
117 | or the | |
bc0d5df3 | 118 | .BR raise (3). |
fea681da MK |
119 | Integer division by zero has undefined result. |
120 | On some architectures it will generate a | |
121 | .B SIGFPE | |
122 | signal. | |
123 | (Also dividing the most negative integer by \-1 may generate | |
124 | .BR SIGFPE .) | |
125 | Ignoring this signal might lead to an endless loop. | |
126 | .PP | |
197362df MK |
127 | See |
128 | .BR sigaction (2) | |
129 | for details on what happens when | |
fea681da MK |
130 | .B SIGCHLD |
131 | is set to | |
132 | .BR SIG_IGN . | |
fea681da | 133 | .PP |
7f82d75e MK |
134 | See |
135 | .BR signal (7) | |
988db661 | 136 | for a list of the async-signal-safe functions that can be |
7f82d75e MK |
137 | safely called inside from inside a signal handler. |
138 | .PP | |
fea681da MK |
139 | The use of |
140 | .B sighandler_t | |
141 | is a GNU extension. | |
142 | Various versions of libc predefine this type; libc4 and libc5 define | |
143 | .IR SignalHandler , | |
144 | glibc defines | |
145 | .I sig_t | |
146 | and, when | |
147 | .B _GNU_SOURCE | |
148 | is defined, also | |
149 | .IR sighandler_t . | |
8c87824d MK |
150 | .SS Portability |
151 | The original Unix | |
152 | .BR signal () | |
8bd58774 MK |
153 | would reset the handler to |
154 | .BR SIG_DFL , | |
155 | and System V | |
8c87824d MK |
156 | (and the Linux kernel and libc4,5) does the same. |
157 | On the other hand, BSD does not reset the handler, but blocks | |
158 | new instances of this signal from occurring during a call of the handler. | |
d9bfdb9c | 159 | The glibc2 library follows the BSD behavior. |
8c87824d MK |
160 | |
161 | If one on a libc5 system includes | |
c84371c6 | 162 | .I <bsd/signal.h> |
8c87824d | 163 | instead of |
c84371c6 | 164 | .I <signal.h> |
8c87824d MK |
165 | then |
166 | .BR signal () | |
167 | is redefined as | |
bc0d5df3 MK |
168 | .BR __bsd_signal () |
169 | and | |
170 | .BR signal () | |
171 | has the BSD semantics. | |
8c87824d MK |
172 | This is not recommended. |
173 | ||
174 | If one on a glibc2 system defines a feature test | |
175 | macro such as | |
176 | .B _XOPEN_SOURCE | |
177 | or uses a separate | |
bc0d5df3 | 178 | .BR sysv_signal (3) |
d9bfdb9c | 179 | function, one obtains classical behavior. |
8c87824d | 180 | This 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) |