SIGNAL(2)

NAME
signal, sigaction, sigsuspend, sigpending, sgetmask, ssetmask - signal handling functions.

SYNOPSIS
#include <signal.h>
#include <unistd.h>
int sigaction(int signum, const struct sigaction *new,
struct sigaction *old);
void (*signal(int signum, (void *handler)(int))))(int)
sigsuspend(int restart, sigset_t old_mask, sigset_t set);
int sigpending(sigset_t *buf);
sigset_t sgetmask (void);
sigset_t ssetmask (sigset_t mask);

DESCRIPTION
sgetmask() and ssetmask() get and set the mask of blocked signals. Signals are bitmapped into this mask as 1 << (signum - 1). Both return the old value of the mask. Note that SIGKILL and SIGSTOP cannot be blocked.

sigpending() fills in *buf with which signals are pending but blocked. 0 is returned.

sigsuspend() is used to atomically swap out the signal mask, while waiting for a signal. If the restart flag is set, then the current mask is replaced with old_mask, and sigsuspend exists with a -EINTR. Otherwise, the current signal mask is set to set, a pause() system call performed, and -ERESTARTNOINTR is returned.

signal() is used to set up a signal handler for signum. The signal handler is set to handler, which may be a user specified function or one of these from signal.h:
SIG_DFL - use the default handler.
SIG_IGN - ignore signal.

Note that signal() sets up signals to be SA_ONESHOT and SA_NOMASK. This may be changed by a call to sigaction().

Also note that SIG_KILL and SIG_STOP cannot be changed.

The address of the handler is returned on success, a negative value on error.

sigaction() is similar to a more general version of signal(). It can be used to set the entire sigaction structure for a signal.

If old is non null, the old action will be stored there. The action will then be set to new.

The structure is as defined in /usr/include/signal.h :
struct sigaction {
void (*sa_handler)(int);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
};

0 is returned on success. Note that SIGKILL and SIGSTOP may not have signals set for them.

ERRORS
-EINVAL is returned when an invalid signum is passed to the functions.

FILES
linux/signal.h
/usr/include/linux/sys.h
/usr/include/unistd.h

SEE ALSO
kill(2), raise(3)

BUGS
signal() and the code in sched.c, signal.c cannot correctly handle a SIG_DFL handler.