sigaction(2) — System Calls
OSF
NAME
sigaction, signal − Specifies the action to take upon delivery of a signal
SYNOPSIS
#include <signal.h>
int sigaction (
int signal,
const struct sigaction ∗action,
struct sigaction ∗o_action ); void (∗signal(
int signal,
void (∗function)( int ) ) ) ( int );
PARAMETERS
signalDefines the signal.
actionPoints to a sigaction structure that describes the action to be taken upon receipt of the signal parameter.
o_actionPoints to a sigaction structure in which the signal action data in effect at the time the sigaction() function is returned.
functionSpecifies the action associated with a signal.
DESCRIPTION
The sigaction() function allows the calling process to examine and/or change the action to be taken when a specific signal is delivered to the process issuing this function.
The signal parameter specifies the signal. If the action parameter is not null, it points to a sigaction structure that describes the action to be taken on receipt of the signal parameter signal. If the o_action parameter is not null, it points to a sigaction structure in which the signal action data in effect at the time of the sigaction() call is returned. If the action parameter is null, signal handling is unchanged; thus, the call can be used to inquire about the current handling of a given signal.
The sigaction structure has the following members: void(∗sa_handler)();
sigset_tsa_mask;
intsa_flags;
The sa_handler field can have the SIG_DFL or SIG_IGN value, or can point to a function. A SIG_DFL value requests default action to be taken when the signal is delivered. A value of SIG_IGN requests that the signal have no effect on the receiving process. A pointer to a function requests that the signal be caught; that is, the signal should cause the function to be called. These actions are more fully described in the signal.h file.
The sa_mask field can be used to specify that individual signals, in addition to those in the process signal mask, be blocked from being delivered while the signal handler function specified in sa_handler is executing. The sa_flags field can have the SA_ONSTACK, SA_RESTART, or SA_NOCLDSTOP bits set to specify further control over the actions taken on delivery of a signal.
If the SA_ONSTACK bit is set, the system runs the signal-catching function on the signal stack specified by the sigstack() function. If this bit is not set, the function runs on the stack of the process to which the signal is delivered.
If the signal parameter is SIGCHLD and a child process of the calling process stops, a SIGCHLD signal will be sent to the calling process if and only if SA_NOCLDSTOP is not set for SIGCHLD.
If a signal for which a signal-catching function exists is sent to a process while that process is executing certain system calls, the call can be restarted if the SA_RESTART bit is set. The affected system calls are the read() and write() functions on a slow device (such as a terminal, but not a regular file) and the wait() function. If SA_RESTART is not set, and such a system call is interrupted by a signal which is caught, then the system call returns -1 and sets errno to [EINTR].
The signal parameter can be any one of the signal values defined in the signal.h header file, except SIGKILL.
The signal() function is provided for compatibility with older versions of UNIX operating systems. It sets the action associated with a signal. The function parameter can have the same values that are described for the sa_handler field in the sigaction structure of the sigaction() function. However, no signal handler mask or flags can be specified.
The effect of calling the signal() function differs in some details depending on whether the calling program is linked with either of the special libraries libbsd or libsys5. If neither library is used, the behavior is the same as that of the sigaction() function with all flags set to 0 (zero). If the libbsd library is used (through compilation with the -lbsd switch), the behavior is the same as that of the sigaction() function with the SA_RESTART flag set. If the libsys5 library is used (though compilation with the -lsys5 switch), then the specified signal is not blocked from delivery when the handler is entered, and the disposition of the signal reverts to SIG_DFL when the signal is delivered.
NOTES
In a multi-threaded environment, the sigaction() function should only be used for the synchronous signals.
The sigvec() and signal() functions are provided for compatibility to old UNIX systems; their function is a subset of that available with the sigaction() function.
AES Support Level:
Full use
RETURN VALUES
Upon successful completion of the sigaction() function, a value of 0 (zero) is returned. If the sigaction() function fails, a value of -1 is returned and errno is set to indicate the error.
Upon successful completion of a signal() function, the value of the previous signal action is returned. If the call fails, a value of -1 is returned and errno is set to indicate the error as in the sigaction() call.
ERRORS
If the sigaction() function fails, no new signal handler is installed and errno may be set to one of the following values:
[EFAULT]The action or o_action parameter points to a location outside of the allocated address space of the process.
[EINVAL]The signal parameter is not a valid signal number.
[EINVAL]An attempt was made to ignore or supply a handler for the SIGKILL, SIGSTOP, and SIGCONT signals.
RELATED INFORMATION
Functions: acct(2), exit(2), kill(2), pause(3), ptrace(2), setjmp(3), sigblock(2), sigpause(3), sigprocmask(2), sigstack(2), sigsuspend(2), sigvec(2), umask(2), wait(2)
Commands: kill(1)
Files: signal(4)