|
|
HP-UX Reference Volume 3 of 5 > ssignal(2) |
|
NAMEsignal, sigset, sighold, sigrelse, sigignore, sigpause — signal management SYNOPSIS#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); DESCRIPTIONThe signal() function chooses one of three ways in which receipt of the signal number sig is to be subsequently handled. If the value of func is SIG_DFL, default handling for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored. Otherwise, func must point to a function to be called when that signal occurs. Such a function is called a signal handler. When a signal occurs, if func points to a function, first the equivalent of a: signal(sig, SIG_DFL); is executed or an implementation-dependent blocking of the signal is performed. (If the value of sig is SIGILL, whether the reset to SIG_DFL occurs is implementation-dependent.) Next the equivalent of: (*func)(sig); is executed. The func function may terminate by executing a return statement or by calling abort(), exit(), or longjmp(). If func() executes a return statement and the value of sig was SIGFPE or any other implementation-dependent value corresponding to a computational exception, the behaviour is undefined. Otherwise, the program will resume execution at the point it was interrupted. If the signal occurs other than as the result of calling abort(), kill() or raise(), the behaviour is undefined if the signal handler calls any function in the standard library other than one of the functions listed on the sigaction(2) page or refers to any object with static storage duration other than by assigning a value to a static storage duration variable of type volatile sig_atomic_t. Furthermore, if such a call fails, the value of errno is indeterminate. At program startup, the equivalent of: signal(sig, SIG_IGN); is executed for some signals, and the equivalent of: signal(sig, SIG_DFL); is executed for all other signals (see exec). The sigset(), sighold(), sigignore(), sigpause() and segrelse() functions provide simplified signal management. The sigset() function is used to modify signal dispositions. The sig argument specifies the signal, which may be any signal except SIGKILL and SIGSTOP. The disp argument specifies the signal's disposition, which may be SIG_DFL, SIG_IGN or the address of a signal handler. If sigset() is used, and disp is the address of a signal handler, the system will add sig to the calling process' signal mask before executing the signal handler; when the signal handler returns, the system will restore the calling process' signal mask to its state prior the delivery of the signal. In addition, if sigset() is used, and disp is equal to SIG_HOLD, sig will be added to the calling process' signal mask and sig's disposition will remain unchanged. If sigset() is used, and disp is not equal to SIG_HOLD, sig will be removed from the calling process' signal mask. The sighold() function adds sig to the calling process' signal mask. The sigrelse() function removes sig from the calling process' signal mask. The sigignore() function sets the disposition of sig to SIG_IGN. The sigpause() function removes sig from the calling process' signal mask and suspends the calling process until a signal is received. If the action for the SIGCHLD signal is set to SIG_IGN, child processes of the calling processes will not be transformed into zombie processes when they terminate. If the calling process subsequently waits for its children, and the process has no unwaited for children that were transformed into zombie processes, it will block until all of its children terminate, and wait(), wait3(), waitid() and waitpid() will fail and set errno to ECHILD. RETURN VALUEIf the request can be honoured, signal() returns the value of func() for the most recent call to signal() for the specified signal sig. Otherwise, SIG_ERR is returned and a positive value is stored in errno. Upon successful completion, sigset() returns SIG_HOLD if the signal had been blocked and the signal's previous disposition if it had not been blocked. Otherwise, SIG_ERR is returned and errno is set to indicate the error. For all other functions, upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORSThe signal() function will fail if:
The signal() function may fail if:
The sigset(), sighold(), sigrelse(), sigignore(), and sigpause() functions will fail if:
The sigset(), and sigignore() functions will fail if:
APPLICATION USAGEThe sigaction() function provides a more comprehensive and reliable mechanism for controlling signals; new applications should use sigaction() rather than signal(). The sighold() function, in conjunction with sigrelse() or sigpause(), may be used to establish critical regions of code that require the delivery of a signal to be temporarily deferred. The sigsuspend() function should be used in preference to sigpause() for broader portability. Threads ConsiderationsThe signal disposition (such as catch/ignore/default) established by signal() is shared by all threads in the process. Blocked signal masks are maintained by each thread. If signal() is used to set the signal disposition for sig to SIG_IGN or to SIG_DFL for a signal whose default action is to ignore the signal, any instances of sig pending on the process or any of the threads will be discarded. The signals are discarded regardless of whether the signal is blocked by any of the threads. For more information regarding signals and threads, refer to signal(5). Issue 4The following changes are incorporated for alignment with the ISO C standard:
Another change is incorporated as follows:
Issue 4, Version 2The following changes are incorporated for X/OPEN UNIX conformance:
SYNOPSIS (HP-UX)void (*signal(int sig, void (*action)(int)))(int); void (*sigset(int sig, void (*func)(int)))(int); DESCRIPTIONThe system defines a set of signals that can be delivered to a process. The set of signals is defined in signal(5), along with the meaning and side effects of each signal. An alternate mechanism for handling these signals is defined here. The facilities described here should not be used in conjunction with the other facilities described under signal(2), sigvector(2), sigblock(2), sigsetmask(2), sigpause(3C), and sigspace(2). Acceptable values for sig are defined in <signal.h>.
sigset() allows the calling process to choose one of four ways to handle the receipt of a specific signal. sig specifies the signal and func specifies the choice.
sighold() holds the signal sig. sigrelse() restores the system signal action of sig to that specified previously by sigset(). sighold() and sigrelse() are used to establish critical regions of code. sighold() is analogous to raising the priority level and deferring or holding a signal until the priority is lowered by sigrelse(). sigignore() sets the action for signal sig to SIG_IGN (see signal(5)). sigpause() suspends the calling process until it receives an unblocked signal. If the signal sig is held, it is released before the process pauses. sigpause() is useful for testing variables that are changed when a signal occurs. For example, sighold() should be used to block the signal first, then test the variables. If they have not changed, call sigpause() to wait for the signal. These functions can be linked into a program by giving the -lV3 option to the ld command (see ld(1)). ERRORSsigset() fails and the system signal action for sig is not changed if any of the following occur:
sigset(), sighold(), sigrelse(), sigignore(), and sigpause() fail and the system signal action for sig is not changed if any of the following occur:
sigpause returns when the following occurs:
EXAMPLESThe following call to signal() sets up a signal-catching function for the SIGINT signal: void myhandler(); (void) signal(SIGINT, myhandler); WARNINGSsignal() should not be used in conjunction with the facilities described under bsdproc(3C), sigaction(2), sigset(3C), or sigvector(2). signal() does not detect an invalid value for action, and if it does not equal SIG_DFL or SIG_IGN, or point to a valid function address, subsequent receipt of the signal sig causes undefined results. SEE ALSOkill(1), init(1M), exit(2), kill(2), lseek(2), pause(2), sigaction(2), sigvector(2), wait(2), abort(3C), setjmp(3C), signal(5). |
|