A child created via fork(2) inherits a copy of its parent's
signal dispositions. During an execve(2), the dispositions of
handled signals are reset to the default; the dispositions of
ignored signals are left unchanged.
According to POSIX, the behavior of a process is undefined after
it ignores a SIGFPE
, SIGILL
, or SIGSEGV
signal that was not
generated by kill(2) or raise(3). Integer division by zero has
undefined result. On some architectures it will generate a
SIGFPE
signal. (Also dividing the most negative integer by -1
may generate SIGFPE
.) Ignoring this signal might lead to an
endless loop.
POSIX.1-1990 disallowed setting the action for SIGCHLD
to
SIG_IGN
. POSIX.1-2001 and later allow this possibility, so that
ignoring SIGCHLD
can be used to prevent the creation of zombies
(see wait(2)). Nevertheless, the historical BSD and System V
behaviors for ignoring SIGCHLD
differ, so that the only
completely portable method of ensuring that terminated children
do not become zombies is to catch the SIGCHLD
signal and perform
a wait(2) or similar.
POSIX.1-1990 specified only SA_NOCLDSTOP
. POSIX.1-2001 added
SA_NOCLDSTOP
, SA_NOCLDWAIT
, SA_NODEFER
, SA_ONSTACK
, SA_RESETHAND
,
SA_RESTART
, and SA_SIGINFO
. Use of these latter values in
sa_flags may be less portable in applications intended for older
UNIX implementations.
The SA_RESETHAND
flag is compatible with the SVr4 flag of the
same name.
The SA_NODEFER
flag is compatible with the SVr4 flag of the same
name under kernels 1.3.9 and later. On older kernels the Linux
implementation allowed the receipt of any signal, not just the
one we are installing (effectively overriding any sa_mask
settings).
sigaction
() can be called with a NULL second argument to query
the current signal handler. It can also be used to check whether
a given signal is valid for the current machine by calling it
with NULL second and third arguments.
It is not possible to block SIGKILL
or SIGSTOP
(by specifying
them in sa_mask). Attempts to do so are silently ignored.
See sigsetops(3) for details on manipulating signal sets.
See signal-safety(7) for a list of the async-signal-safe
functions that can be safely called inside from inside a signal
handler.
C library/kernel differences
The glibc wrapper function for sigaction
() gives an error
(EINVAL
) on attempts to change the disposition of the two real-
time signals used internally by the NPTL threading
implementation. See nptl(7) for details.
On architectures where the signal trampoline resides in the C
library, the glibc wrapper function for sigaction
() places the
address of the trampoline code in the act.sa_restorer field and
sets the SA_RESTORER
flag in the act.sa_flags field. See
sigreturn(2).
The original Linux system call was named sigaction
(). However,
with the addition of real-time signals in Linux 2.2, the fixed-
size, 32-bit sigset_t type supported by that system call was no
longer fit for purpose. Consequently, a new system call,
rt_sigaction
(), was added to support an enlarged sigset_t type.
The new system call takes a fourth argument, size_t sigsetsize,
which specifies the size in bytes of the signal sets in
act.sa_mask and oldact.sa_mask. This argument is currently
required to have the value sizeof(sigset_t) (or the error EINVAL
results). The glibc sigaction
() wrapper function hides these
details from us, transparently calling rt_sigaction
() when the
kernel provides it.
Undocumented
Before the introduction of SA_SIGINFO
, it was also possible to
get some additional information about the signal. This was done
by providing an sa_handler signal handler with a second argument
of type struct sigcontext, which is the same structure as the one
that is passed in the uc_mcontext field of the ucontext structure
that is passed (via a pointer) in the third argument of the
sa_sigaction handler. See the relevant Linux kernel sources for
details. This use is obsolete now.