1SIGNAL(2)                  Linux Programmer's Manual                 SIGNAL(2)
2
3
4

NAME

6       signal - ANSI C signal handling
7

SYNOPSIS

9       #include <signal.h>
10
11       typedef void (*sighandler_t)(int);
12
13       sighandler_t signal(int signum, sighandler_t handler);
14

DESCRIPTION

16       WARNING:  the behavior of signal() varies across UNIX versions, and has
17       also varied historically across different versions of Linux.  Avoid its
18       use: use sigaction(2) instead.  See Portability below.
19
20       signal() sets the disposition of the signal signum to handler, which is
21       either SIG_IGN, SIG_DFL, or the address of a  programmer-defined  func‐
22       tion (a "signal handler").
23
24       If  the signal signum is delivered to the process, then one of the fol‐
25       lowing happens:
26
27       *  If the disposition is set to SIG_IGN, then the signal is ignored.
28
29       *  If the disposition is set to SIG_DFL, then the default action  asso‐
30          ciated with the signal (see signal(7)) occurs.
31
32       *  If  the disposition is set to a function, then first either the dis‐
33          position is reset to SIG_DFL, or the signal is blocked  (see  Porta‐
34          bility  below), and then handler is called with argument signum.  If
35          invocation of the handler caused the signal to be blocked, then  the
36          signal is unblocked upon return from the handler.
37
38       The signals SIGKILL and SIGSTOP cannot be caught or ignored.
39

RETURN VALUE

41       signal()  returns  the previous value of the signal handler On failure,
42       it returns SIG_ERR, and errno is set to indicate the error.
43

ERRORS

45       EINVAL signum is invalid.
46

CONFORMING TO

48       POSIX.1-2001, POSIX.1-2008, C89, C99.
49

NOTES

51       The effects of signal() in a multithreaded process are unspecified.
52
53       According to POSIX, the behavior of a process is undefined after it ig‐
54       nores  a  SIGFPE,  SIGILL,  or SIGSEGV signal that was not generated by
55       kill(2) or raise(3).  Integer division by zero  has  undefined  result.
56       On some architectures it will generate a SIGFPE signal.  (Also dividing
57       the most negative integer by -1 may generate  SIGFPE.)   Ignoring  this
58       signal might lead to an endless loop.
59
60       See  sigaction(2)  for  details  on  what  happens when the disposition
61       SIGCHLD is set to SIG_IGN.
62
63       See signal-safety(7) for a list of the async-signal-safe functions that
64       can be safely called from inside a signal handler.
65
66       The  use  of sighandler_t is a GNU extension, exposed if _GNU_SOURCE is
67       defined; glibc also defines  (the  BSD-derived)  sig_t  if  _BSD_SOURCE
68       (glibc  2.19  and earlier) or _DEFAULT_SOURCE (glibc 2.19 and later) is
69       defined.  Without use of such a type, the decl