SIGNAL(2)
NAME
signal − specify what to do upon receipt of a signal
SYNOPSIS
#include <signal.h>
int (∗signal (sig, func))()
int sig;
int (∗func)(); func(sig [, code, scp ] )
int sig, code;
struct sigcontext ∗scp;
HP-UX COMPATIBILITY
Level: HP-UX/RUN ONLY
Origin: System V, HP
DESCRIPTION
Signal allows the calling process to choose one of three ways in which it is possible to handle the receipt of a specific signal. Sig specifies the signal and func specifies the choice.
Sig can be assigned any one of the following except SIGKILL:
SIGHUP01hangup
SIGINT02interrupt
SIGQUIT03∗quit
SIGILL04∗•illegal instruction
SIGTRAP05∗•trace trap
SIGIOT06∗software generated (sent by abort(3C))
SIGEMT07∗software generated
SIGFPE08∗floating point exception
SIGKILL09‡+kill
SIGBUS10∗bus error
SIGSEGV11∗segmentation violation
SIGSYS12∗bad argument to system call
SIGPIPE13write on a pipe with no one to read it
SIGALRM14alarm clock
SIGTERM15software termination signal
SIGUSR116user defined signal 1
SIGUSR217user defined signal 2
SIGCLD18†death of a child (see details below)
SIGPWR19•†power fail (see details below and hardware dependencies)
SIGVTALRM20virtual timer alarm; see getitimer
SIGPROF21profiling timer alarm; see getitimer
SIGIO22Reserved for future use
SIGWINDOW23† A window change or mouse signal; see the windowing package
∗ Indicates that a core dump may be generated.
† Indicates that the action on SIG_DFL is to ignore the signal, rather than terminate the process.
• Indicates that the signal is not reset when it is caught by signal.
‡ Indicates that the signal cannot be ignored.
+ Indicates that the signal cannot be caught.
Details follow.
Func is assigned one of three values: SIG_DFL, SIG_IGN, or a function address. The actions prescribed by these values are as follows:
SIG_DFL − (usually) terminate process upon receipt of a signal.
For those signals not flagged with a dagger (†) above, upon receipt of the signal sig, the receiving process is to be terminated with all of the consequences outlined in exit(2). In addition a “core image” will be made in the current working directory of the receiving process if sig is one for which an asterisk appears in the above list and the following conditions are met:
The effective user ID and the real user ID of the receiving process are equal.
An ordinary file named core exists and is writable or can be created. If the file must be created, it will have the following properties:
a mode of 0666 modified by the file creation mask (see umask(2))
a file owner ID that is the same as the effective user ID of the receiving process
a file group ID that is the same as the effective group ID of the receiving process
The semantics of those signals that are flagged with a dagger are discussed below.
SIG_IGN − ignore signal
The signal sig is to be ignored.
When signal(2) is called with func = SIG_IGN, and a sig signal is pending, the pending signal is cleared (except for a pending SIGKILL signal).
Note: the signal SIGKILL cannot be ignored.
function address − catch signal
Upon receipt of the signal sig, the receiving process is to execute the signal-catching function pointed to by func. The signal number sig will be passed as the first parameter to the signal-catching function. The HP-UX kernel will also pass two additional (optional) parameters to signal handler routines. The complete parameter list for func is:
sig signal number
code a word of information usually provided by the hardware.
scp a pointer to the machine dependent structure sigcontext defined in the include file signal.h.
Depending on the value of sig, code may be zero and/or scp may be NULL. The meanings of code and scp and the conditions upon which they are other than zero or NULL are implementation dependent. It is permissible for code to always be zero, and scp to always be NULL.
The pointer scp will only be valid during the context of the signal handler.
The optional parameters can be omitted from the handler parameter list, in which case the handler is exactly compatible with System V UNIX. Truly portable software should not use the optional parameters in signal-catching routines.
Before entering the signal-catching function, the value of func for the caught signal will be set to SIG_DFL unless the signal is one of those flagged with a bullet (•) above.
Upon return from the signal-catching function, the receiving process will resume execution at the point it was interrupted.
When a signal that is to be caught occurs during calls such as (but not limited to) read, write, readv, writev, open, or an ioctl system call on a slow device such as a terminal (but not a file); during a select, semop, msgsnd, msgrcv, pause, or sigpause system call; or during a wait system call that does not return immediately due to the existence of a previously stopped or zombie process, the signal catching function will be executed. The interrupted system call may return a −1 to the calling process with errno set to EINTR.
Note: The signal SIGKILL cannot be caught.
SIGKILL may be sent by the system in the event of an unsuccessful exec, if the original program has already been deleted.
SPECIAL SIGNALS
SIGCLD, SIGPWR, and B SIGWINDOW signals have special characteristics described below and in hardware dependencies.
For these signals, func is assigned one of three values: SIG_DFL, SIG_IGN, or a function address. The actions prescribed by these values of are as follows:
SIG_DFL - ignore signal (applies to SIGWINDOW as well)
The signal is to be ignored.
SIG_IGN - ignore signal
The signal is to be ignored. Also, if sig is SIGCLD, the calling process’s child processes will not create zombie processes when they terminate; see exit(2).
function address - catch signal
If the signal is SIGPWR, the action to be taken is the same as that described above for func equal to function address. The same is true if the signal is SIGCLD, except that when signal(2) is called to install a signal-catching function, and the calling process currently has terminated (zombie) children, the SIGCLD signal will be immediately sent to the calling process.
NOTE: If a signal-catching routine is used to catch SIGCLD, wait(2) must be called in the catching routine to clear out the pending zombie before signal(2) is called to reinstate the signal-catching routine. Otherwise, the process will enter the signal-catching routine recursively until the process runs out of stack space.
The SIGCLD signal affects two other system calls (wait(2), and exit(2)) in the following ways:
wait If the func value of SIGCLD is set to SIG_IGN and a wait is executed, the wait will block until all of the calling process’s child processes terminate; it will then return a value of −1 with errno set to ECHILD.
exit If in the exiting process’s parent process the func value of SIGCLD is set to SIG_IGN, the exiting process will not create a zombie process.
When processing a pipeline, the shell makes the last process in the pipeline the parent of the preceding processes. A process that may be piped into in this manner (and thus become the parent of other processes) should take care not to set SIGCLD to be caught.
FAIL CONDITIONS
Signal will fail if one or more of the following are true:
[EINVAL] Sig is an illegal signal number, or is equal to SIGKILL.
[EFAULT] Func points to an illegal address.
HARDWARE DEPENDENCIES
Series 200:
The signal SIGPWR is not currently generated.
The code word is always zero for all signals except signal 4 (SIGILL) and signal 8 (SIGFPE). For SIGILL, code has the following values:
0illegal instruction;
6check instruction;
7TRAPV;
8privilege violation.
For SIGFPE, code has the following values:
0floating point exception;
5divide-by-zero.
Refer to the MC68000 processor documentation provided with your system for more detailed information about the meaning of these errors.
Series 500:
Core image files are currently files with zero length.
The SIGEMT signal means "out of memory", and is generated by the HP-UX Operating System. When sent by the system, this signal is always fatal to the process, and cannot be caught or ignored.
SIGIOT can be sent if an invalid string operation is attempted, or if a bounds range check trap is encountered.
The signal SIGBUS is not currently generated by the operating system.
The signal handler parameter code contains the trap number provided by the hardware in the event a trap occurs in the user’s program; see trapno(2) for a list of these trap numbers. The structure pointer scp is defined when a trap occurs in the user’s program, and points to the structure sigcontext defined in signal.h.
A zero value is returned on floating point underflow. Floating point overflow, divide-by-zero, integer divide-by-zero, and illegal floating point operation exceptions result in the signal SIGFPE being sent to the process. An undefined value is returned as the result of the operation if the signal SIGFPE is ignored or caught.
SIGFPE is not sent on integer overflow. Instead, a wrapped integer result is returned.
The signal SIGPWR is generated by the operating system for the HP 9000 Model 550 only, provided that the system is equipped with a standby power supply. Series 500 models 520, 530, and 540 do not currently generate SIGPWR.
When the computer standby power supply is activated due to a loss of line voltage, the operating system determines whether a power glitch or power outage has occurred. The determination is made by waiting about five seconds then re-examining the state of the standby power supply. If the normal line voltage has been restored, code is set to PWR_GLITCH; otherwise, it is set to PWR_OUTAGE. The SIGPWR signal is then sent to all user processes (excluding the INIT process) with the appropriate code value. When normal line power is restored following a power outage, SIGPWR is sent to all user processes (again excluding the INIT process) with code set to PWR_NORMAL.
Integral PC:
The Integral PC implements the signal SIGMOUSE with a value of 20.
The Integral PC does not create core files.
RETURN VALUE
Upon successful completion, signal returns the previous value of func for the specified signal sig. Otherwise, a value of −1 is returned and errno is set to indicate the error.
SEE ALSO
kill(1), kill(2), lseek(2), pause(2), sigvector(2), trapno(2), wait(2), abort(3C), setjmp(3C).
Hewlett-Packard — last mod. May 11, 2021