Home

signalfd4

Signalfd4 is a Linux system call that creates a file descriptor for receiving signals delivered to a process, enabling asynchronous signal handling through I/O multiplexing rather than traditional signal handlers. It is part of the signalfd family, which also includes signalfd (the earlier interface). The signalfd4 variant adds an explicit parameter to control the size of the signal information payload returned to userspace.

The prototype is int signalfd4(int fd, const sigset_t *mask, int flags, size_t siginfo_size). If fd is -1,

Usage typically requires blocking the signals in the set with sigprocmask or pthread_sigmask before creating the

Notes: signalfd4 provides a mechanism to tailor the size of the returned signal information payload and coexists

a
new
signalfd
is
created;
otherwise,
the
provided
file
descriptor
is
reused.
The
mask
argument
points
to
a
set
of
signals
to
be
delivered
via
the
file
descriptor.
The
flags
argument
accepts
SFD_CLOEXEC
to
set
the
close-on-exec
flag
and
SFD_NONBLOCK
to
make
reads
non-blocking.
The
siginfo_size
parameter
specifies
the
size,
in
bytes,
of
the
signal
information
structure
that
will
be
written
to
the
read
buffer
(for
example,
a
signalfd_siginfo
struct).
signalfd,
so
that
signals
are
delivered
to
the
file
descriptor
rather
than
a
traditional
signal
handler.
When
a
blocked
signal
in
the
mask
is
delivered,
the
signalfd
file
descriptor
becomes
readable;
a
read
returns
the
corresponding
signal
information.
This
enables
integration
of
signal
handling
into
event
loops
using
poll,
select,
or
epoll.
with
the
standard
signalfd
interface.
The
API
is
defined
in
sys/signalfd.h,
and
users
typically
work
with
the
signalfd_siginfo
structure
returned
by
reads.