1SIGNAL(3P)                 POSIX Programmer's Manual                SIGNAL(3P)
2
3
4

PROLOG

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

NAME

12       signal — signal management
13

SYNOPSIS

15       #include <signal.h>
16
17       void (*signal(int sig, void (*func)(int)))(int);
18

DESCRIPTION

20       The functionality described on this reference page is aligned with  the
21       ISO C  standard.  Any  conflict between the requirements described here
22       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
23       defers to the ISO C standard.
24
25       The signal() function chooses one of three ways in which receipt of the
26       signal number sig is to be subsequently handled. If the value  of  func
27       is SIG_DFL, default handling for that signal shall occur.  If the value
28       of func is SIG_IGN, the signal shall be ignored.  Otherwise, the appli‐
29       cation  shall  ensure  that func points to a function to be called when
30       that signal occurs. An invocation of such a function because of a  sig‐
31       nal,  or  (recursively) of any further functions called by that invoca‐
32       tion (other than functions in the standard library), is called a ``sig‐
33       nal handler''.
34
35       When  a signal occurs, and func points to a function, it is implementa‐
36       tion-defined whether the equivalent of a:
37
38
39           signal(sig, SIG_DFL);
40
41       is executed or the implementation prevents some  implementation-defined
42       set  of  signals (at least including sig) from occurring until the cur‐
43       rent signal handling has completed. (If the value of sig is SIGILL, the
44       implementation  may alternatively define that no action is taken.) Next
45       the equivalent of:
46
47
48           (*func)(sig);
49
50       is executed. If and when the function returns, if the value of sig  was
51       SIGFPE,  SIGILL,  or  SIGSEGV or any other implementation-defined value
52       corresponding to a computational exception, the behavior is  undefined.
53       Otherwise,  the  program  shall  resume  execution  at the point it was
54       interrupted. The ISO C standard places a  restriction  on  applications
55       relating  to the use of raise() from signal handlers.  This restriction
56       does not apply to POSIX applications, as POSIX.1‐2008 requires  raise()
57       to be async-signal-safe (see Section 2.4.3, Signal Actions).
58
59       If  the process is multi-threaded, or if the process is single-threaded
60       and a signal handler is executed other than as the result of:
61
62        *  The process calling abort(), raise(),  kill(),  pthread_kill(),  or
63           sigqueue() to generate a signal that is not blocked
64
65        *  A  pending  signal  being  unblocked and being delivered before the
66           call that unblocked it returns
67
68       the behavior is undefined if the signal handler refers  to  any  object
69       other than errno with static storage duration other than by assigning a
70       value to an object declared as volatile sig_atomic_t, or if the  signal
71       handler  calls  any function defined in this standard other than one of
72       the functions listed in Section 2.4, Signal Concepts.
73
74       At program start-up, the equivalent of:
75
76
77           signal(sig, SIG_IGN);
78
79       is executed for some signals, and the equivalent of:
80
81
82           signal(sig, SIG_DFL);
83
84       is executed for all other signals (see exec).
85
86       The signal() function shall not change the setting of errno if success‐
87       ful.
88

RETURN VALUE

90       If  the request can be honored, signal() shall return the value of func
91       for the most recent call to signal()  for  the  specified  signal  sig.
92       Otherwise,  SIG_ERR  shall  be  returned  and a positive value shall be
93       stored in errno.
94

ERRORS

96       The signal() function shall fail if:
97
98       EINVAL The sig argument is not a valid signal number or an  attempt  is
99              made  to catch a signal that cannot be caught or ignore a signal
100              that cannot be ignored.
101
102       The signal() function may fail if:
103
104       EINVAL An attempt was made to set the action to SIG_DFL  for  a  signal
105              that cannot be caught or ignored (or both).
106
107       The following sections are informative.
108

EXAMPLES

110       None.
111

APPLICATION USAGE

113       The  sigaction()  function  provides  a more comprehensive and reliable
114       mechanism for controlling signals; new applications should  use  sigac‐
115       tion() rather than signal().
116

RATIONALE

118       None.
119

FUTURE DIRECTIONS

121       None.
122

SEE ALSO

124       Section 2.4, Signal Concepts, exec, pause(), raise(), sigaction(), sig‐
125       suspend(), waitid()
126
127       The Base Definitions volume of POSIX.1‐2017, <signal.h>
128
130       Portions of this text are reprinted and reproduced in  electronic  form
131       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
132       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
133       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
134       Electrical and Electronics Engineers, Inc and The Open Group.   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.opengroup.org/unix/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                  2017                           SIGNAL(3P)
Impressum