summaryrefslogtreecommitdiffstats
path: root/upstream/archlinux/man3p/signal.3p
blob: 366e0b7b271e00b3e9be8b3555de5f187f977958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
'\" et
.TH SIGNAL "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
signal
\(em signal management
.SH SYNOPSIS
.LP
.nf
#include <signal.h>
.P
void (*signal(int \fIsig\fP, void (*\fIfunc\fP)(int)))(int);
.fi
.SH DESCRIPTION
The functionality described on this reference page is aligned with the
ISO\ C standard. Any conflict between the requirements described here and the
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
.P
The
\fIsignal\fR()
function chooses one of three ways in which receipt of the signal
number
.IR sig
is to be subsequently handled. If the value of
.IR func
is SIG_DFL, default handling for that signal shall occur.
If the value of
.IR func
is SIG_IGN, the signal shall be ignored.
Otherwise, the application shall ensure that
.IR func
points to a function to be called when that signal occurs. An
invocation of such a function because of a signal, or (recursively) of
any further functions called by that invocation (other than functions
in the standard library), is called a ``signal handler''.
.P
When a signal occurs, and
.IR func
points to a function, it is implementation-defined whether the
equivalent of a:
.sp
.RS 4
.nf

signal(\fIsig\fP, SIG_DFL);
.fi
.P
.RE
.P
is executed or the implementation prevents some implementation-defined
set of signals (at least including
.IR sig )
from occurring until the current signal handling has completed. (If the
value of
.IR sig
is SIGILL, the implementation may alternatively define that no action
is taken.) Next the equivalent of:
.sp
.RS 4
.nf

(*func)(sig);
.fi
.P
.RE
.P
is executed. If and when the function returns, if the value of
.IR sig
was SIGFPE, SIGILL, or SIGSEGV or any other implementation-defined
value corresponding to
a computational exception, the behavior is undefined. Otherwise, the
program shall resume execution at the point it was interrupted. The
ISO\ C standard places a restriction on applications relating to the use of
\fIraise\fR()
from signal handlers.
This restriction does not apply to POSIX applications, as POSIX.1\(hy2008 requires
\fIraise\fR()
to be async-signal-safe (see
.IR "Section 2.4.3" ", " "Signal Actions").
.P
If the process is multi-threaded,
or if the process is single-threaded and a signal handler is
executed other than as the result of:
.IP " *" 4
The process calling
\fIabort\fR(),
\fIraise\fR(),
\fIkill\fR(),
\fIpthread_kill\fR(),
or
\fIsigqueue\fR()
to generate a signal that is not blocked
.IP " *" 4
A pending signal being unblocked and being delivered before the call
that unblocked it returns
.P
the behavior is undefined if the signal handler refers to any object
other than
.IR errno
with static storage duration other than by assigning a value to an
object declared as
.BR "volatile sig_atomic_t" ,
or if the signal handler calls any function defined in this standard
other than
one of the functions listed in
.IR "Section 2.4" ", " "Signal Concepts".
.P
At program start-up, the equivalent of:
.sp
.RS 4
.nf

signal(\fIsig\fP, SIG_IGN);
.fi
.P
.RE
.P
is executed for some signals, and the equivalent of:
.sp
.RS 4
.nf

signal(\fIsig\fP, SIG_DFL);
.fi
.P
.RE
.P
is executed for all other signals
(see
.IR exec ).
.P
The
\fIsignal\fR()
function shall not change the setting of
.IR errno
if successful.
.SH "RETURN VALUE"
If the request can be honored,
\fIsignal\fR()
shall return the value of
.IR func
for the most recent call to
\fIsignal\fR()
for the specified signal
.IR sig .
Otherwise, SIG_ERR shall be returned and a positive value shall
be stored in
.IR errno .
.SH ERRORS
The
\fIsignal\fR()
function shall fail if:
.TP
.BR EINVAL
The
.IR sig
argument is not a valid signal number or an attempt is made to catch a
signal that cannot be caught or ignore a signal that cannot be
ignored.
.P
The
\fIsignal\fR()
function may fail if:
.TP
.BR EINVAL
An attempt was made to set the action to SIG_DFL for a signal that
cannot be caught or ignored (or both).
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
The
\fIsigaction\fR()
function provides a more comprehensive and reliable mechanism for
controlling signals; new applications should use
\fIsigaction\fR()
rather than
\fIsignal\fR().
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.4" ", " "Signal Concepts",
.IR "\fIexec\fR\^",
.IR "\fIpause\fR\^(\|)",
.IR "\fIraise\fR\^(\|)",
.IR "\fIsigaction\fR\^(\|)",
.IR "\fIsigsuspend\fR\^(\|)",
.IR "\fIwaitid\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<signal.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .