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