signal(2)
NAME
signal − specify what to do upon receipt of a signal
SYNOPSIS
#include <signal.h>
void (*signal(int sig, void (*action)(int)))(int);
DESCRIPTION
signal() allows the calling process to choose one of three ways to handle the receipt of a specific signal. sig specifies the signal and action specifies the choice.
Acceptable values for sig are defined in <signal.h>. The specific signals are described in full in the signal(5) manual entry.
The value of the action argument specifies what to do upon the receipt of signal sig, and should be one of the following:
SIG_DFL Execute the default action, which varies depending on the signal. The default action for most signals is to terminate the process (see signal(5)).
A pending signal is discarded (whether or not it is blocked) if action is set to SIG_DFL but the default action of the pending signal is to ignore the signal (as in the case of SIGCLD).
SIG_IGN Ignore the signal.
When signal() is called with action set to SIG_IGN and an instance of the signal sig is pending, the pending signal is discarded, whether or not it is blocked.
SIGKILL and SIGSTOP signals cannot be ignored.
address Catch the signal.
Upon receipt of signal sig, reset the value of action for the caught signal to SIG_DFL (except signals marked with "not reset when caught"; see signal(5)), call the signal-catching function to which address points, and resume executing the receiving process at the point where it was interrupted.
The signal-catching function is called with the following three parameters:
sig The signal number.
code A word of information usually provided by the hardware.
scp A pointer to the machine-dependent structure sigcontext defined in <signal.h>.
Depending on the value of sig, code can be zero and/or scp can be NULL. The meanings of code and scp and the conditions determining when they are other than zero or NULL are implementation dependent (see DEPENDENCIES below). It is possible for code to always be zero, and scp to always be NULL.
The pointer scp is valid only during the context of the signal-catching function.
The signals SIGKILL and SIGSTOP cannot be caught.
RETURN VALUE
Upon successful completion, signal() returns the previous value of action for the specified signal sig. Otherwise, a value of SIG_ERR is returned and errno is set to indicate the error.
ERRORS
signal() fails if the following is true:
[EINVAL] sig is an illegal signal number, or is equal to SIGKILL or SIGSTOP.
EXAMPLES
The following call to signal() sets up a signal-catching function for the SIGINT signal:
void myhandler();
(void) signal(SIGINT, myhandler);
WARNINGS
signal() should not be used in conjunction with the facilities described under bsdproc(2), sigaction(2), sigset(2V), 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.
DEPENDENCIES
Series 300/400
The code word is always zero for all signals except SIGILL and SIGFPE. For SIGILL, code has the following values:
0 illegal instruction;
6 check instruction;
7 TRAPV;
8 privilege violation.
Refer to the MC6800xx processor documentation for more detailed information about the meaning of the SIGILL errors.
For SIGFPE, code has the following values:
0 software floating point exception;
5 integer divide-by-zero.
0x8xxxxxx any value with the high-order bit set indicates an exception while using the HP98248 floating-point accelerator. The value of (code &~ 0x8000000) is the value of the HP98248 status register. Refer to the HP98248 documentation for more detailed information.
other any other value indicates an exception while using the MC68881 or MC68882 floating-point coprocessor. The value of code is the value of the MC68881 or MC68882 status register. Refer to the MC68881 documentation for more detailed information.
Series 700/800
The structure pointer scp is always defined.
The code word is always zero for all signals except SIGILL and SIGFPE. For SIGILL, code has the following values:
8 illegal instruction trap;
9 break instruction trap;
10 privileged operation trap;
11 privileged register trap.
For SIGFPE, code has the following values:
12 overflow trap;
13 conditional trap;
14 assist exception trap;
22 assist emulation trap.
As defined by the IEEE POSIX Standard, HP-UX on Series 700/800 systems does not raise an exception on floating-point divide by zero. The result of floating-point divide by zero is infinity which can be checked by isinf(3M).
AUTHOR
signal() was developed by HP, AT&T, and the University of California, Berkeley.
SEE ALSO
kill(1), init(1M), exit(2), kill(2), lseek(2), pause(2), sigaction(2), sigvector(2), wait(2), abort(3C), setjmp(3C), signal(5).
STANDARDS CONFORMANCE
signal(): AES, SVID2, XPG2, XPG3, XPG4, ANSI C
Hewlett-Packard Company — HP-UX Release 9.10: April 1995