Go to the previous, next section.

sigaction and signal

SYNOPSIS

int sigaction(int signum, const struct sigaction *new, struct sigaction *old);

(void *) (int) signal(int signum, (void *handler)(int));

PARAMETERS

signum: [in] a signal number.

new: [in] the action to take for this signal.

old: [out] the previous action that was associated to the signal.

handler: [in] points to the new signal handler.

DESCRIPTION

sigaction is used to specify the action to take in case the signal signum is raised. signum can take one of the following values:

SIGHUP
(terminates) the controling terminal has been disconnected.

SIGINT
(terminates) the interrupt key has been pressed (Ctrl-C usually).

SIGQUIT
(terminates and dumps core) the quit key has been pressed (Ctrl-\ usually).

SIGILL
(terminates and dumps core) the task has executed an illegal instruction (or is ill?).

SIGTRAP
(terminates and dumps core) caught an hardware fault.

SIGABRT
(terminates and dumps core) usually generated by the abort function.

SIGIOT
(terminates and dumps core) caught an hardware fault.

SIGUNUSED
(terminates) unused.

SIGFPE
(terminates and dumps core) the task has generated a floating-point exception.

SIGKILL
(terminates) kills the task. This signal can't be caught or ignored.

SIGUSR1
(terminates) user defined signal.

SIGSEGV
(terminates and dumps core) the task has made an invalid memory reference.

SIGUSR2
(terminates) user defined signal.

SIGPIPE
(terminates) the task tried to write to a pipe/socket but the reader is dead.

SIGALRM
(terminates) an alarm has expired.

SIGTERM
(terminates) termination signal.

SIGSTKFLT
??

SIGCHLD
(ignore) a child has died.

SIGCONT
(ignored or resumes) send to a stopped task to make it resume its execution.

SIGSTOP
(stops) send to a task to make it stop its execution. This signal can't be caught or ignored.

SIGTSTP
(stops) interactive stop signal generated by the terminal (usually Ctrl-Z).

SIGTTIN
(stops) the process is in background and tried to read from its controling terminal.

SIGTTOU
(stops) the process is in background and tried to write to its controling terminal.

SIGIO
(terminates) an asynchronous I/O event has occured.

SIGPOLL
(terminates) an event has occurend on a pooling device.

SIGURG
(terminates) an urgent condition has occured. (Usually the reception of out-of-band data on a network connection.)

SIGXCPU
(terminates) the task has exceeded its CPU time limit.

SIGXFSZ
(terminates) the taks exceeds its size limit.

SIGVTALRM
(terminates) a virtual interval timer has expired.

SIGPROF
(terminates) a profiling interval timer has expired.

SIGWINCH
(ignored) the controling terminal size has changed.

SIGPWR
(terminates) power failure: run for cover!

SIGBUS
(terminates) a hardware fault has occured. If we look in the kernel sources, we see: Arggh. Bad user source code wants this.

There is also a signal SIGLOST in the sources, however it is commented out.

The action to take is specified by a sigcaction structure that has the following layout:

struct sigaction {
	__sighandler_t sa_handler;  /* the handler (or a special value) */
	sigset_t sa_mask;           /* signals to block on entry */
	int sa_flags;               /* some flags */
	void (*sa_restorer)(void);  /* not used */
};

sa_handler may be set to the address of the handler to start to handle the signal or it may be set to one of the following special values:

SIG_ING
means to ignore the signal.

SIG_DFL
means to use the default handler.

sa_mask specifies signals to be added to the signal mask of the process before calling the signal handler. The signal mask is restored to its initial value upon return from the handler.

sa_flags specifies some options for the handling of the signal:

SA_NOCLDSTOP
disable the generation of the SIGCHLD signal when a child stops. signum must be SIGCHLD.

SA_RESTART
ask for automatic restart of system calls interrupted by this signal.

SA_STACK
not implemented.

SA_INTERRUPT
ignored.

SA_NOMASK
do not mask anything (not even the current signal). (Looks like SA_NODEFER in [Stevens].)

SA_ONESHOT
the handler will be used only once. (Looks like SA_RESETHAND in [Stevens].)

The previous value of the sigaction structure for the signal is stored to the area pointed to by old.

signal is some kind of proto-sigaction. It sets the handler of signum to handler. It is equivalent to

struct sigaction new;
new.sa_handler=handler;
new.sa_mask=0;
new.sa_flags=SA_NOMASK | SA_ONESHOT;
new.sa_restorer=NULL;
sigaction(signum, &new, NULL);

It could be implemented as a sigaction wrapper.

RETURN VALUE

On success, sigaction returns zero and signal returns the pointer to the signal handler. On error, both return -1. The possible values of errno are:

Go to the previous, next section.