1signal.h(0P) POSIX Programmer's Manual signal.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 signal.h — signals
13
15 #include <signal.h>
16
18 Some of the functionality described on this reference page extends the
19 ISO C standard. Applications shall define the appropriate feature test
20 macro (see the System Interfaces volume of POSIX.1‐2017, Section 2.2,
21 The Compilation Environment) to enable the visibility of these symbols
22 in this header.
23
24 The <signal.h> header shall define the following macros, which shall
25 expand to constant expressions with distinct values that have a type
26 compatible with the second argument to, and the return value of, the
27 signal() function, and whose values shall compare unequal to the
28 address of any declarable function.
29
30 SIG_DFL Request for default signal handling.
31
32 SIG_ERR Return value from signal() in case of error.
33
34 SIG_HOLD Request that signal be held.
35
36 SIG_IGN Request that signal be ignored.
37
38 The <signal.h> header shall define the pthread_t, size_t, and uid_t
39 types as described in <sys/types.h>.
40
41 The <signal.h> header shall define the timespec structure as described
42 in <time.h>.
43
44 The <signal.h> header shall define the following data types:
45
46 sig_atomic_t Possibly volatile-qualified integer type of an object
47 that can be accessed as an atomic entity, even in the
48 presence of asynchronous interrupts.
49
50 sigset_t Integer or structure type of an object used to represent
51 sets of signals.
52
53 pid_t As described in <sys/types.h>.
54
55 The <signal.h> header shall define the pthread_attr_t type as described
56 in <sys/types.h>.
57
58 The <signal.h> header shall define the sigevent structure, which shall
59 include at least the following members:
60
61
62 int sigev_notify Notification type.
63 int sigev_signo Signal number.
64 union sigval sigev_value Signal value.
65 void (*sigev_notify_function)(union sigval)
66 Notification function.
67 pthread_attr_t *sigev_notify_attributes Notification attributes.
68
69 The <signal.h> header shall define the following symbolic constants for
70 the values of sigev_notify:
71
72 SIGEV_NONE No asynchronous notification is delivered when the event
73 of interest occurs.
74
75 SIGEV_SIGNAL A queued signal, with an application-defined value, is
76 generated when the event of interest occurs.
77
78 SIGEV_THREAD A notification function is called to perform notifica‐
79 tion.
80
81 The sigval union shall be defined as:
82
83
84 int sival_int Integer signal value.
85 void *sival_ptr Pointer signal value.
86
87 The <signal.h> header shall declare the SIGRTMIN and SIGRTMAX macros,
88 which shall expand to positive integer expressions with type int, but
89 which need not be constant expressions. These macros specify a range of
90 signal numbers that are reserved for application use and for which the
91 realtime signal behavior specified in this volume of POSIX.1‐2017 is
92 supported. The signal numbers in this range do not overlap any of the
93 signals specified in the following table.
94
95 The range SIGRTMIN through SIGRTMAX inclusive shall include at least
96 {RTSIG_MAX} signal numbers.
97
98 It is implementation-defined whether realtime signal behavior is sup‐
99 ported for other signals.
100
101 The <signal.h> header shall define the following macros that are used
102 to refer to the signals that occur in the system. Signals defined here
103 begin with the letters SIG followed by an uppercase letter. The macros
104 shall expand to positive integer constant expressions with type int and
105 distinct values. The value 0 is reserved for use as the null signal
106 (see kill()). Additional implementation-defined signals may occur in
107 the system.
108
109 The ISO C standard only requires the signal names SIGABRT, SIGFPE, SIG‐
110 ILL, SIGINT, SIGSEGV, and SIGTERM to be defined. An implementation need
111 not generate any of these six signals, except as a result of explicit
112 use of interfaces that generate signals, such as raise(), kill(), the
113 General Terminal Interface (see Section 11.1.9, Special Characters),
114 and the kill utility, unless otherwise stated (see, for example, the
115 System Interfaces volume of POSIX.1‐2017, Section 2.8.3.3, Memory Pro‐
116 tection).
117
118 The following signals shall be supported on all implementations
119 (default actions are explained below the table):
120
121 ┌──────────┬────────────────┬────────────────────────────────────────────────────┐
122 │ Signal │ Default Action │ Description │
123 ├──────────┼────────────────┼────────────────────────────────────────────────────┤
124 │SIGABRT │ A │ Process abort signal. │
125 │SIGALRM │ T │ Alarm clock. │
126 │SIGBUS │ A │ Access to an undefined portion of a memory object. │
127 │SIGCHLD │ I │ Child process terminated, stopped, │
128 │ │ │ or continued. │
129 │SIGCONT │ C │ Continue executing, if stopped. │
130 │SIGFPE │ A │ Erroneous arithmetic operation. │
131 │SIGHUP │ T │ Hangup. │
132 │SIGILL │ A │ Illegal instruction. │
133 │SIGINT │ T │ Terminal interrupt signal. │
134 │SIGKILL │ T │ Kill (cannot be caught or ignored). │
135 │SIGPIPE │ T │ Write on a pipe with no one to read it. │
136 │SIGQUIT │ A │ Terminal quit signal. │
137 │SIGSEGV │ A │ Invalid memory reference. │
138 │SIGSTOP │ S │ Stop executing (cannot be caught or ignored). │
139 │SIGTERM │ T │ Termination signal. │
140 │SIGTSTP │ S │ Terminal stop signal. │
141 │SIGTTIN │ S │ Background process attempting read. │
142 │SIGTTOU │ S │ Background process attempting write. │
143 │SIGUSR1 │ T │ User-defined signal 1. │
144 │SIGUSR2 │ T │ User-defined signal 2. │
145 │SIGPOLL │ T │ Pollable event. │
146 │SIGPROF │ T │ Profiling timer expired. │
147 │SIGSYS │ A │ Bad system call. │
148 │SIGTRAP │ A │ Trace/breakpoint trap. │
149 │SIGURG │ I │ High bandwidth data is available at a socket. │
150 │SIGVTALRM │ T │ Virtual timer expired. │
151 │SIGXCPU │ A │ CPU time limit exceeded. │
152 │SIGXFSZ │ A │ File size limit exceeded. │
153 │ │ │ │
154 └──────────┴────────────────┴────────────────────────────────────────────────────┘
155 The default actions are as follows:
156
157 T Abnormal termination of the process.
158
159 A Abnormal termination of the process with additional actions.
160
161 I Ignore the signal.
162
163 S Stop the process.
164
165 C Continue the process, if it is stopped; otherwise, ignore the
166 signal.
167
168 The effects on the process in each case are described in the System
169 Interfaces volume of POSIX.1‐2017, Section 2.4.3, Signal Actions.
170
171 The <signal.h> header shall declare the sigaction structure, which
172 shall include at least the following members:
173
174
175 void (*sa_handler)(int) Pointer to a signal-catching function
176 or one of the SIG_IGN or SIG_DFL.
177 sigset_t sa_mask Set of signals to be blocked during execution
178 of the signal handling function.
179 int sa_flags Special flags.
180 void (*sa_sigaction)(int, siginfo_t *, void *)
181 Pointer to a signal-catching function.
182
183 The storage occupied by sa_handler and sa_sigaction may overlap, and a
184 conforming application shall not use both simultaneously.
185
186 The <signal.h> header shall define the following macros which shall
187 expand to integer constant expressions that need not be usable in #if
188 preprocessing directives:
189
190 SIG_BLOCK The resulting set is the union of the current set and the
191 signal set pointed to by the argument set.
192
193 SIG_UNBLOCK The resulting set is the intersection of the current set
194 and the complement of the signal set pointed to by the
195 argument set.
196
197 SIG_SETMASK The resulting set is the signal set pointed to by the
198 argument set.
199
200 The <signal.h> header shall also define the following symbolic con‐
201 stants:
202
203 SA_NOCLDSTOP Do not generate SIGCHLD when children stop
204 or stopped children continue.
205
206 SA_ONSTACK Causes signal delivery to occur on an alternate stack.
207
208 SA_RESETHAND Causes signal dispositions to be set to SIG_DFL on entry
209 to signal handlers.
210
211 SA_RESTART Causes certain functions to become restartable.
212
213 SA_SIGINFO Causes extra information to be passed to signal handlers
214 at the time of receipt of a signal.
215
216 SA_NOCLDWAIT Causes implementations not to create zombie processes or
217 status information on child termination. See sigaction().
218
219 SA_NODEFER Causes signal not to be automatically blocked on entry to
220 signal handler.
221
222 SS_ONSTACK Process is executing on an alternate signal stack.
223
224 SS_DISABLE Alternate signal stack is disabled.
225
226 MINSIGSTKSZ Minimum stack size for a signal handler.
227
228 SIGSTKSZ Default size in bytes for the alternate signal stack.
229
230 The <signal.h> header shall define the mcontext_t type through typedef.
231
232 The <signal.h> header shall define the ucontext_t type as a structure
233 that shall include at least the following members:
234
235
236 ucontext_t *uc_link Pointer to the context that is resumed
237 when this context returns.
238 sigset_t uc_sigmask The set of signals that are blocked when this
239 context is active.
240 stack_t uc_stack The stack used by this context.
241 mcontext_t uc_mcontext A machine-specific representation of the saved
242 context.
243
244 The <signal.h> header shall define the stack_t type as a structure,
245 which shall include at least the following members:
246
247
248 void *ss_sp Stack base or pointer.
249 size_t ss_size Stack size.
250 int ss_flags Flags.
251
252 The <signal.h> header shall define the siginfo_t type as a structure,
253 which shall include at least the following members:
254
255
256 int si_signo Signal number.
257 int si_code Signal code.
258 int si_errno If non-zero, an errno value associated with
259 this signal, as described in <errno.h>.
260 pid_t si_pid Sending process ID.
261 uid_t si_uid Real user ID of sending process.
262 void *si_addr Address of faulting instruction.
263 int si_status Exit value or signal.
264 long si_band Band event for SIGPOLL.
265 union sigval si_value Signal value.
266
267 The <signal.h> header shall define the symbolic constants in the Code
268 column of the following table for use as values of si_code that are
269 signal-specific or non-signal-specific reasons why the signal was gen‐
270 erated.
271
272┌───────┬─────────────┬──────────────────────────────────────────────────────────────────┐
273│Signal │ Code │ Reason │
274├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
275│SIGILL │ILL_ILLOPC │Illegal opcode. │
276│ │ILL_ILLOPN │Illegal operand. │
277│ │ILL_ILLADR │Illegal addressing mode. │
278│ │ILL_ILLTRP │Illegal trap. │
279│ │ILL_PRVOPC │Privileged opcode. │
280│ │ILL_PRVREG │Privileged register. │
281│ │ILL_COPROC │Coprocessor error. │
282│ │ILL_BADSTK │Internal stack error. │
283├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
284│SIGFPE │FPE_INTDIV │Integer divide by zero. │
285│ │FPE_INTOVF │Integer overflow. │
286│ │FPE_FLTDIV │Floating-point divide by zero. │
287│ │FPE_FLTOVF │Floating-point overflow. │
288│ │FPE_FLTUND │Floating-point underflow. │
289│ │FPE_FLTRES │Floating-point inexact result. │
290│ │FPE_FLTINV │Invalid floating-point operation. │
291│ │FPE_FLTSUB │Subscript out of range. │
292├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
293│SIGSEGV│SEGV_MAPERR │Address not mapped to object. │
294│ │SEGV_ACCERR │Invalid permissions for mapped object. │
295├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
296│SIGBUS │BUS_ADRALN │Invalid address alignment. │
297│ │BUS_ADRERR │Nonexistent physical address. │
298│ │BUS_OBJERR │Object-specific hardware error. │
299├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
300│SIGTRAP│TRAP_BRKPT │Process breakpoint. │
301│ │TRAP_TRACE │Process trace trap. │
302├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
303│SIGCHLD│CLD_EXITED │Child has exited. │
304│ │CLD_KILLED │Child has terminated abnormally and did not create a core file. │
305│ │CLD_DUMPED │Child has terminated abnormally and created a core file. │
306│ │CLD_TRAPPED │Traced child has trapped. │
307│ │CLD_STOPPED │Child has stopped. │
308│ │CLD_CONTINUED│Stopped child has continued. │
309├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
310│SIGPOLL│POLL_IN │Data input available. │
311│ │POLL_OUT │Output buffers available. │
312│ │POLL_MSG │Input message available. │
313│ │POLL_ERR │I/O error. │
314│ │POLL_PRI │High priority input available. │
315│ │POLL_HUP │Device disconnected. │
316├───────┼─────────────┼──────────────────────────────────────────────────────────────────┤
317│Any │SI_USER │Signal sent by kill(). │
318│ │SI_QUEUE │Signal sent by sigqueue(). │
319│ │SI_TIMER │Signal generated by expiration of a timer set by timer_settime(). │
320│ │SI_ASYNCIO │Signal generated by completion of an asynchronous I/O │
321│ │ │request. │
322│ │SI_MESGQ │Signal generated by arrival of a message on an empty message │
323│ │ │queue. │
324└───────┴─────────────┴──────────────────────────────────────────────────────────────────┘
325 Implementations may support additional si_code values not included in
326 this list, may generate values included in this list under circum‐
327 stances other than those described in this list, and may contain exten‐
328 sions or limitations that prevent some values from being generated.
329 Implementations do not generate a different value from the ones
330 described in this list for circumstances described in this list.
331
332 In addition, the following signal-specific information shall be avail‐
333 able:
334
335 ┌────────┬────────────────┬───────────────────────────────────────────────────┐
336 │Signal │ Member │ Value │
337 ├────────┼────────────────┼───────────────────────────────────────────────────┤
338 │SIGILL │ void * si_addr │ Address of faulting instruction. │
339 │SIGFPE │ │ │
340 ├────────┼────────────────┼───────────────────────────────────────────────────┤
341 │SIGSEGV │ void * si_addr │ Address of faulting memory reference. │
342 │SIGBUS │ │ │
343 ├────────┼────────────────┼───────────────────────────────────────────────────┤
344 │SIGCHLD │ pid_t si_pid │ Child process ID. │
345 │ │ int si_status │ If si_code is equal to CLD_EXITED, then si_status │
346 │ │ │ holds the exit value of the process; otherwise, │
347 │ │ │ it is equal to the signal that caused the process │
348 │ │ │ to change state. The exit value in si_status │
349 │ │ │ shall be equal to the full exit value (that is, │
350 │ │ │ the value passed to _exit(), _Exit(), or exit(), │
351 │ │ │ or returned from main()); it shall not be limited │
352 │ │ │ to the least significant eight bits of the value. │
353 │ │ uid_t si_uid │ Real user ID of the process that sent the signal. │
354 ├────────┼────────────────┼───────────────────────────────────────────────────┤
355 │SIGPOLL │ long si_band │ Band event for POLL_IN, POLL_OUT, or POLL_MSG. │
356 └────────┴────────────────┴───────────────────────────────────────────────────┘
357 For some implementations, the value of si_addr may be inaccurate.
358
359 The following shall be declared as functions and may also be defined as
360 macros. Function prototypes shall be provided.
361
362
363 int kill(pid_t, int);
364 int killpg(pid_t, int);
365 void psiginfo(const siginfo_t *, const char *);
366 void psignal(int, const char *);
367 int pthread_kill(pthread_t, int);
368 int pthread_sigmask(int, const sigset_t *restrict,
369 sigset_t *restrict);
370 int raise(int);
371 int sigaction(int, const struct sigaction *restrict,
372 struct sigaction *restrict);
373 int sigaddset(sigset_t *, int);
374 int sigaltstack(const stack_t *restrict, stack_t *restrict);
375 int sigdelset(sigset_t *, int);
376 int sigemptyset(sigset_t *);
377 int sigfillset(sigset_t *);
378 int sighold(int);
379 int sigignore(int);
380 int siginterrupt(int, int);
381 int sigismember(const sigset_t *, int);
382 void (*signal(int, void (*)(int)))(int);
383 int sigpause(int);
384 int sigpending(sigset_t *);
385 int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict);
386 int sigqueue(pid_t, int, union sigval);
387 int sigrelse(int);
388 void (*sigset(int, void (*)(int)))(int);
389 int sigsuspend(const sigset_t *);
390 int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict,
391 const struct timespec *restrict);
392 int sigwait(const sigset_t *restrict, int *restrict);
393 int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict);
394
395 Inclusion of the <signal.h> header may make visible all symbols from
396 the <time.h> header.
397
398 The following sections are informative.
399
401 On systems not supporting the XSI option, the si_pid and si_uid members
402 of siginfo_t are only required to be valid when si_code is SI_USER or
403 SI_QUEUE. On XSI-conforming systems, they are also valid for all
404 si_code values less than or equal to 0; however, it is unspecified
405 whether SI_USER and SI_QUEUE have values less than or equal to zero,
406 and therefore XSI applications should check whether si_code has the
407 value SI_USER or SI_QUEUE or is less than or equal to 0 to tell whether
408 si_pid and si_uid are valid.
409
411 None.
412
414 The SIGPOLL and SIGPROF signals may be removed in a future version.
415
417 <errno.h>, <stropts.h>, <sys_types.h>, <time.h>
418
419 The System Interfaces volume of POSIX.1‐2017, Section 2.2, The Compila‐
420 tion Environment, alarm(), ioctl(), kill(), killpg(), psiginfo(),
421 pthread_kill(), pthread_sigmask(), raise(), sigaction(), sigaddset(),
422 sigaltstack(), sigdelset(), sigemptyset(), sigfillset(), sighold(),
423 siginterrupt(), sigismember(), signal(), sigpending(), sigqueue(), sig‐
424 suspend(), sigtimedwait(), sigwait(), timer_create(), wait(), waitid()
425
426 The Shell and Utilities volume of POSIX.1‐2017, kill
427
429 Portions of this text are reprinted and reproduced in electronic form
430 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
431 table Operating System Interface (POSIX), The Open Group Base Specifi‐
432 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
433 Electrical and Electronics Engineers, Inc and The Open Group. In the
434 event of any discrepancy between this version and the original IEEE and
435 The Open Group Standard, the original IEEE and The Open Group Standard
436 is the referee document. The original Standard can be obtained online
437 at http://www.opengroup.org/unix/online.html .
438
439 Any typographical or formatting errors that appear in this page are
440 most likely to have been introduced during the conversion of the source
441 files to man page format. To report such errors, see https://www.ker‐
442 nel.org/doc/man-pages/reporting_bugs.html .
443
444
445
446IEEE/The Open Group 2017 signal.h(0P)