1SIGNAL(3P) POSIX Programmer's Manual SIGNAL(3P)
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
11
13 signal — signal management
14
16 #include <signal.h>
17
18 void (*signal(int sig, void (*func)(int)))(int);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 Use of this function is unspecified in a multi-threaded process.
27
28 The signal() function chooses one of three ways in which receipt of the
29 signal number sig is to be subsequently handled. If the value of func
30 is SIG_DFL, default handling for that signal shall occur. If the value
31 of func is SIG_IGN, the signal shall be ignored. Otherwise, the appli‐
32 cation shall ensure that func points to a function to be called when
33 that signal occurs. An invocation of such a function because of a sig‐
34 nal, or (recursively) of any further functions called by that invoca‐
35 tion (other than functions in the standard library), is called a ``sig‐
36 nal handler''.
37
38 When a signal occurs, and func points to a function, it is implementa‐
39 tion-defined whether the equivalent of a:
40
41 signal(sig, SIG_DFL);
42
43 is executed or the implementation prevents some implementation-defined
44 set of signals (at least including sig) from occurring until the cur‐
45 rent signal handling has completed. (If the value of sig is SIGILL, the
46 implementation may alternatively define that no action is taken.) Next
47 the equivalent of:
48
49 (*func)(sig);
50
51 is executed. If and when the function returns, if the value of sig was
52 SIGFPE, SIGILL, or SIGSEGV or any other implementation-defined value
53 corresponding to a computational exception, the behavior is undefined.
54 Otherwise, the program shall resume execution at the point it was
55 interrupted. The ISO C standard places a restriction on applications
56 relating to the use of raise() from signal handlers. This restriction
57 does not apply to POSIX applications, as POSIX.1‐2008 requires raise()
58 to be async-signal-safe (see Section 2.4.3, Signal Actions).
59
60 If the process is multi-threaded, or if the process is single-threaded
61 and a signal handler is executed other than as the result of:
62
63 * The process calling abort(), raise(), kill(), pthread_kill(), or
64 sigqueue() to generate a signal that is not blocked
65
66 * A pending signal being unblocked and being delivered before the
67 call that unblocked it returns
68
69 the behavior is undefined if the signal handler refers to any object
70 other than errno with static storage duration other than by assigning a
71 value to an object declared as volatile sig_atomic_t, or if the signal
72 handler calls any function defined in this standard other than one of
73 the functions listed in Section 2.4, Signal Concepts.
74
75 At program start-up, the equivalent of:
76
77 signal(sig, SIG_IGN);
78
79 is executed for some signals, and the equivalent of:
80
81 signal(sig, SIG_DFL);
82
83 is executed for all other signals (see exec).
84
85 The signal() function shall not change the setting of errno if success‐
86 ful.
87
89 If the request can be honored, signal() shall return the value of func
90 for the most recent call to signal() for the specified signal sig.
91 Otherwise, SIG_ERR shall be returned and a positive value shall be
92 stored in errno.
93
95 The signal() function shall fail if:
96
97 EINVAL The sig argument is not a valid signal number or an attempt is
98 made to catch a signal that cannot be caught or ignore a signal
99 that cannot be ignored.
100
101 The signal() function may fail if:
102
103 EINVAL An attempt was made to set the action to SIG_DFL for a signal
104 that cannot be caught or ignored (or both).
105
106 The following sections are informative.
107
109 None.
110
112 The sigaction() function provides a more comprehensive and reliable
113 mechanism for controlling signals; new applications should use sigac‐
114 tion() rather than signal().
115
117 None.
118
120 None.
121
123 Section 2.4, Signal Concepts, exec, pause(), raise(), sigaction(), sig‐
124 suspend(), waitid()
125
126 The Base Definitions volume of POSIX.1‐2008, <signal.h>
127
129 Portions of this text are reprinted and reproduced in electronic form
130 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
131 -- Portable Operating System Interface (POSIX), The Open Group Base
132 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
133 cal and Electronics Engineers, Inc and The Open Group. (This is
134 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
135 event of any discrepancy between this version and the original IEEE and
136 The Open Group Standard, the original IEEE and The Open Group Standard
137 is the referee document. The original Standard can be obtained online
138 at http://www.unix.org/online.html .
139
140 Any typographical or formatting errors that appear in this page are
141 most likely to have been introduced during the conversion of the source
142 files to man page format. To report such errors, see https://www.ker‐
143 nel.org/doc/man-pages/reporting_bugs.html .
144
145
146
147IEEE/The Open Group 2013 SIGNAL(3P)