SIGNAL(3)                  POSIX Programmer's Manual                 SIGNAL(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       signal -- signal management

SSYYNNOOPPSSIISS
       #include <signal.h>

       void (*signal(int _s_i_g, void (*_f_u_n_c)(int)))(int);

DDEESSCCRRIIPPTTIIOONN
       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-2017
       defers to the ISO C standard.

       The _s_i_g_n_a_l() function chooses one of three ways in which receipt of the
       signal number _s_i_g is to be subsequently handled. If the value of _f_u_n_c
       is SIG_DFL, default handling for that signal shall occur.  If the value
       of _f_u_n_c is SIG_IGN, the signal shall be ignored.  Otherwise, the
       application shall ensure that _f_u_n_c 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''.

       When a signal occurs, and _f_u_n_c points to a function, it is
       implementation-defined whether the equivalent of a:


           signal(_s_i_g, SIG_DFL);

       is executed or the implementation prevents some implementation-defined
       set of signals (at least including _s_i_g) from occurring until the
       current signal handling has completed. (If the value of _s_i_g is SIGILL,
       the implementation may alternatively define that no action is taken.)
       Next the equivalent of:


           (*func)(sig);

       is executed. If and when the function returns, if the value of _s_i_g 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 _r_a_i_s_e() from signal handlers.  This restriction
       does not apply to POSIX applications, as POSIX.1-2008 requires _r_a_i_s_e()
       to be async-signal-safe (see _S_e_c_t_i_o_n _2_._4_._3, _S_i_g_n_a_l _A_c_t_i_o_n_s).

       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:

        *  The process calling _a_b_o_r_t(), _r_a_i_s_e(), _k_i_l_l(), _p_t_h_r_e_a_d___k_i_l_l(), or
           _s_i_g_q_u_e_u_e() to generate a signal that is not blocked

        *  A pending signal being unblocked and being delivered before the
           call that unblocked it returns

       the behavior is undefined if the signal handler refers to any object
       other than _e_r_r_n_o with static storage duration other than by assigning a
       value to an object declared as vvoollaattiillee ssiigg__aattoommiicc__tt, or if the signal
       handler calls any function defined in this standard other than one of
       the functions listed in _S_e_c_t_i_o_n _2_._4, _S_i_g_n_a_l _C_o_n_c_e_p_t_s.

       At program start-up, the equivalent of:


           signal(_s_i_g, SIG_IGN);

       is executed for some signals, and the equivalent of:


           signal(_s_i_g, SIG_DFL);

       is executed for all other signals (see _e_x_e_c).

       The _s_i_g_n_a_l() function shall not change the setting of _e_r_r_n_o if
       successful.

RREETTUURRNN VVAALLUUEE
       If the request can be honored, _s_i_g_n_a_l() shall return the value of _f_u_n_c
       for the most recent call to _s_i_g_n_a_l() for the specified signal _s_i_g.
       Otherwise, SIG_ERR shall be returned and a positive value shall be
       stored in _e_r_r_n_o.

EERRRROORRSS
       The _s_i_g_n_a_l() function shall fail if:

       EEIINNVVAALL The _s_i_g 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.

       The _s_i_g_n_a_l() function may fail if:

       EEIINNVVAALL An attempt was made to set the action to SIG_DFL for a signal
              that cannot be caught or ignored (or both).

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _s_i_g_a_c_t_i_o_n() function provides a more comprehensive and reliable
       mechanism for controlling signals; new applications should use
       _s_i_g_a_c_t_i_o_n() rather than _s_i_g_n_a_l().

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._4, _S_i_g_n_a_l _C_o_n_c_e_p_t_s, _e_x_e_c, _p_a_u_s_e(), _r_a_i_s_e(), _s_i_g_a_c_t_i_o_n(),
       _s_i_g_s_u_s_p_e_n_d(), _w_a_i_t_i_d()

       The Base Definitions volume of POSIX.1-2017, <<ssiiggnnaall..hh>>

CCOOPPYYRRIIGGHHTT
       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 .

       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 .



IEEE/The Open Group                  2017                            SIGNAL(3)
