1signalfd(2)                   System Calls Manual                  signalfd(2)
2
3
4

NAME

6       signalfd - create a file descriptor for accepting signals
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/signalfd.h>
13
14       int signalfd(int fd, const sigset_t *mask, int flags);
15

DESCRIPTION

17       signalfd() creates a file descriptor that can be used to accept signals
18       targeted at the caller.  This provides an alternative to the use  of  a
19       signal  handler  or sigwaitinfo(2), and has the advantage that the file
20       descriptor may be monitored by select(2), poll(2), and epoll(7).
21
22       The mask argument specifies the set of signals that the  caller  wishes
23       to accept via the file descriptor.  This argument is a signal set whose
24       contents can be initialized using the macros described in sigsetops(3).
25       Normally,  the  set  of  signals to be received via the file descriptor
26       should be blocked using sigprocmask(2), to prevent  the  signals  being
27       handled according to their default dispositions.  It is not possible to
28       receive SIGKILL or SIGSTOP signals  via  a  signalfd  file  descriptor;
29       these signals are silently ignored if specified in mask.
30
31       If  the  fd argument is -1, then the call creates a new file descriptor
32       and associates the signal set specified in mask with that file descrip‐
33       tor.   If  fd is not -1, then it must specify a valid existing signalfd
34       file descriptor, and mask is used to replace the signal set  associated
35       with that file descriptor.
36
37       Starting with Linux 2.6.27, the following values may be bitwise ORed in
38       flags to change the behavior of signalfd():
39
40       SFD_NONBLOCK  Set the O_NONBLOCK file status flag on the open file  de‐
41                     scription  (see  open(2)) referred to by the new file de‐
42                     scriptor.  Using this flag saves extra calls to  fcntl(2)
43                     to achieve the same result.
44
45       SFD_CLOEXEC   Set  the  close-on-exec (FD_CLOEXEC) flag on the new file
46                     descriptor.  See the description of the O_CLOEXEC flag in
47                     open(2) for reasons why this may be useful.
48
49       Up to Linux 2.6.26, the flags argument is unused, and must be specified
50       as zero.
51
52       signalfd() returns a file descriptor that supports the following opera‐
53       tions:
54
55       read(2)
56              If  one  or more of the signals specified in mask is pending for
57              the process, then the buffer supplied to read(2) is used to  re‐
58              turn  one  or  more signalfd_siginfo structures (see below) that
59              describe the signals.  The read(2) returns  information  for  as
60              many signals as are pending and will fit in the supplied buffer.
61              The buffer must  be  at  least  sizeof(struct  signalfd_siginfo)
62              bytes.   The  return value of the read(2) is the total number of
63              bytes read.
64
65              As a consequence of the read(2), the signals  are  consumed,  so
66