Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

signal, sighold, sigignore, sigpause, sigrelse, sigset - examine or change signal handling

&pagelevel(4)&pagelevel

Syntax

#include <signal.h>

void ( *signal(int sig, void ( * func)(int)))(int);

int sighold(int sig);

int sigignore(int sig);

int sigpause(int sig);

int sigrelse(int sig);

void ( *sigset(int sig, void ( *disp)(int)))(int);

Description

signal() defines how the receipt of a signal is to be subsequently handled.

sig may be any signal defined by the system, except SIGKILL and SIGSTOP (see signal.h).

func () defines the signal action. The following values are possible:

  • SIG_DFL (default signal handling)

  • SIG_IGN (ignore the signal)

  • Address of a signal-handling function (also called a signal handler) In this case, the system adds the signal sig to the signal mask of the calling process before the signal handler is executed. On exiting the signal-handler, the system restores the signal mask of the calling process to the existing state before the signal was received.

If func () points to a function, the following steps are performed in sequence when a signal occurs:

  1. An equivalent of the following signal function is executed:

    signal( sig, SIG_DFL);

    If the value of sig in this example is SIGILL, a reset to SIG_DFL occurs.

  2. An equivalent of the following function is executed next:

    ( *func )( sig );

The signal-handling function func () may be terminated by a return statement or by an abort(), exit(), or longjmp() function. If func () executes a return statement and the value of sig is SIGFPE, SIGILL or SIGDVZ, the behavior is undefined. Otherwise, the program will resume execution at the point it was interrupted.

If a signal occurs without abort(), kill() or raise() being called, the behavior is undefined if the signal handler calls an X/Open-conformant library function other than one of those listed in the table under sigaction() or if an object of static storage duration other than a variable of type volatile sig_atomic_t is accessed. If such a call fails, the value of errno is indeterminate.

At program startup, the equivalent of the following function is executed for some signals:

signal( sig, SIG_IGN);

An equivalent of the following function is executed for all other signals (see exec):

signal( sig, SIG_DFL);

The functions sigset(), sighold(), sigignore(), sigpause() and sigrelse() simplify signal management for application processes.

sigset() is used to modify signal handling. sig indicates the signal, which can be any one except SIGKILL and SIGSTOP. disp defines the handling of the signal, which can be SIG_DFL, SIG_IGN or the address of a signal-handling routine. If sigset() is used and disp is the address of a signal-handling routine, the system adds the signal sig to the signal mask of the calling process before the signal-handling routine is executed. When execution of the signal-handling routine terminates, the system resets the signal mask of the calling process to the status it had before the signal was received. If sigset() is used and disp equals SIG_HOLD, then sig is added to the signal mask of the calling process, and the signal handling remains unchanged.

sighold() adds sig to the signal mask of the calling process.

sigrelse() removes sig from the signal mask of the calling process.

sigignore() sets the handling of sig to SIG_IGN.

sigpause() removes sig from the signal mask of the calling process and deactivates the calling process until a signal is received.

If one of the above functions is used to set the handling of SIGCHLD to SIG_IGN, the child processes of the calling process will not generate any zombie processes when they are terminated. If the calling process waits for its child processes consecutively, it blocks until all its child processes are terminated. The value -1 is then returned and errno contains the error ID ECHILD (see wait(), waitid(), waitpid()).

Return val.

Value of func () on successful completion.

 

SIG_ERR

if an error occurs, e.g. if sig is not a valid signal number or func () points to an invalid address. errno is set to indicate the error.

 

SIG_HOLD

returned by sigset() on successful completion if the signal was blocked. If it was not blocked, sigset() returns the previous handling.

 

SIG_ERR

if an error occurs in sigset(), errno contains the relevant error ID.

 

All other functions return zero if successful. If an error occurs they return -1 and set errno

Errors

signal() will fail if:

 

EINVAL

sig is an invalid signal number
or an attempt was made to catch a signal that cannot be caught or to ignore a signal that cannot be ignored or to set the action to SIG_DFL for a signal that can be neither caught nor ignored.

 

BS2000


 

EFAULT

Invalid address. (End)

 

sigset(), sighold(), sigrelse(), sigignore() and sigpause() will fail if:

 

EINVAL

sig is an invalid signal number
or with sigset() and sigignore() an attempt was made to catch a signal that cannot be caught or to ignore a signal that cannot be ignored.

Notes

sigaction() provides a more comprehensive and reliable mechanism for controlling
signals than signal(); new applications should therefore use sigaction().

sighold() in conjunction with sigrelse() or sigpause() can be used to create critical
program areas in which the receipt of a signal can be temporarily deactivated.The sigsuspend() function can be used instead of sigpause() to increase the portability. 

See also

exec, pause(), sigaction(), waitid(), signal.h.