|
|
#include <signal.h>int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
If both act and oact are NULL, sigaction( ) has no effect except to verify that sig is within the valid range of signal numbers. EINVAL is returned if sig is out of range.
union { void (*sa_handler)(int); void (*sa_sigaction)(int, siginfo_t *, void *); } sigset_t sa_mask; int sa_flags;These members are defined as:
sa_handler
sa_handler
is set,
the sa_sigaction
member must not be set.
sa_sigaction
sa_sigaction
is set,
the sa_handler
member must not be set.
For details of the sa_sigaction
member, see the
SA_SIGINFO flag, below.
sa_mask
sa_handler
or sa_sigaction
member
specifies a signal-catching function.
On entry to the signal handler,
that set of signals is added to the set of signals
already being blocked when the signal is delivered.
In addition, the signal that caused the
handler to be executed will also be blocked,
unless the SA_NODEFER flag has been specified.
SIGSTOP and SIGKILL cannot be blocked
(the system silently enforces this restriction).
sa_flags
The SA_ONSTACK flag specifies that whenever the process receives the signal type sig the response is handled on an alternative stack. The location and size of the alternative stack is specified per process.
Alternate signal handling stacks can be defined via the sigaltstack(S-osr5) system call.
Additionally, if this flag is set, sigaction behaves as if the SA_NODEFER flag were also set.
sa_mask
.
void func(int signo);where signo is passed as the only argument to the signal-catching function. In such cases, set
sa_handler
to describe the signal-catching function
and do not set sa_sigaction
.
If SA_SIGINFO is set and the signal is caught, two additional arguments are passed to the signal-catching function. If the second argument is not NULL, it points to a siginfo_t structure containing the reason why the signal was generated (see siginfo(FP)); the third argument points to a ucontext_t structure containing the receiving process's context, as interrupted when the signal was delivered (see ucontext(FP)).
In this case, populate the sa_sigaction
member
to describe the signal-catching function
and do not set the sa_handler
member.
The members of the
siginfo(FP)
structure are set as follows:
si_signo
si_errno
si_signo
is non-zero,
the si_errno
member
contains an error number identifying the the condition
that caused the signal to be generated.
si_code
si_code
is less than or equal to 0,
then the signal was generated by a process and
si_pid
and si_uid
respectively indicate the
process ID and the real user ID of the sender.
sa_flags
, then SIGCHLD is
generated for the calling process whenever any of its child
processes stop. If sig is SIGCHLD and
SA_NOCLDSTOP flag is set in sa_flags
,
SIGCHLD is not generated.
Whenever a signal is caught by a function installed using the
sigaction function, a new signal mask is calculated and
installed for the duration of the function or until
sigprocmask(S-osr5)
or
sigsuspend(S-osr5)
is called. This mask is calculated from the union of the existing
mask and the value of sa_mask
specified for the signal
being delivered, unless SA_NODEFER or
SA_RESETHAND are set, and then including the signal being
delivered. If and when the signal-catching routine returns normally,
the original signal mask is restored.
Once an action has been associated with a signal, it remains in force until another call to sigaction, until the SA_RESETHAND flag resets the handler, or until one of the exec(S-osr5) functions is called.
If the previous action associated with sig had been
established using
signal(S-osr5),
the values of the members returned in the structure indicated by
oact cannot be predicted, and in particular,
oact->sa_handler
is not necessarily the same
value passed to signal. However, if a pointer to the same
structure or a copy of the structure is passed to a subsequent call
of sigaction via the act argument, handling of
the signal is carried out as if the original call to
signal had been repeated.
If sigaction fails, no new signal handler is installed.
AT&T SVID Issue 3;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2)
;
X/Open Portability Guide, Issue 3, 1989
;
X/Open Portability Guide Issue 4, Version 2 (Spec-1170)
and
NIST FIPS 151-1
.