signal(3)signal(3)Namesignal - simplified software signal facilities
Syntax
#include <signal.h>
(*signal(sig, func))()
void (*func)();
Description
The subroutine is a simplified interface to the more general sigvec(2)
facility.
A signal is generated by some abnormal event, initiated by a user at a
terminal (quit, interrupt, stop), by a program error (bus error, etc.),
by request of another program (kill), or when a process is stopped
because it wishes to access its control terminal while in the back‐
ground. For further information, see
signals are optionally generated when a process resumes after being
stopped, when the status of child process changes, or when input is
ready at the control terminal. Most signals cause termination of the
receiving process if no action is taken; some signals instead cause the
process receiving them to be stopped, or are simply discarded if the
process has not requested otherwise. Except for the SIGKILL and
SIGSTOP signals, the call allows signals either to be ignored or to
cause an interrupt to a specified location. The following is a list of
all signals with names as in the include file < signal.h >:
SIGHUP 1 Hangup
SIGINT 2 Interrupt
SIGQUIT 3* Quit
SIGILL 4* Illegal instruction
SIGTRAP 5* Trace trap
SIGIOT 6* IOT instruction
SIGEMT 7* EMT instruction
SIGFPE 8* Floating point exception
SIGKILL 9 Kill (cannot be caught or ignored)
SIGBUS 10* Bus error
SIGSEGV 11* Segmentation violation
SIGSYS 12* Bad argument to system call
SIGPIPE 13 write on a pipe with no one to read it
SIGALRM 14 Alarm clock
SIGTERM 15 Software termination signal
SIGURG 16· Urgent condition present on socket
SIGSTOP 17+ Stop (cannot be caught or ignored)
SIGTSTP 18+ Stop signal generated from keyboard
SIGCONT 19· Continue after stop
SIGCHLD 20· Child status has changed
SIGTTIN 21+ Background read attempted from control terminal
SIGTTOU 22+ Background write attempted to control terminal
SIGIO 23· I/O is possible on a descriptor (see fcntl(2))
SIGXCPU 24 Cpu time limit exceeded (see setrlimit(2))
SIGXFSZ 25 File size limit exceeded (see setrlimit(2))
SIGVTALRM 26 Virtual time alarm (see setitimer(2))
SIGPROF 27 Profiling timer alarm (see setitimer(2))
SIGWINCH 28· Window size change
SIGLOST 29 lock not reclaimed after server recovery
SIGUSR1 30 User defined signal
SIGUSR2 31 User defined signal
SIGCLD System V name for SIGCHLD
SIGABRT X/OPEN name for SIGIOT
The starred signals in the list above cause a core image if not caught
or ignored.
If func is SIG_DFL, the default action for signal sig is reinstated;
this default is termination (with a core image for starred signals)
except for signals marked with · or +. Signals marked with · are dis‐
carded if the action is SIG_DFL; signals marked with + cause the
process to stop. If func is SIG_IGN the signal is subsequently ignored
and pending instances of the signal are discarded. Otherwise, when the
signal occurs further occurrences of the signal are automatically
blocked and func is called.
A return from the function unblocks the handled signal and continues
the process at the point it was interrupted. Unlike previous signal
facilities, the handler func remains installed after a signal has been
delivered.
If a caught signal occurs during certain system calls, causing the call
to terminate prematurely, the call is automatically restarted. In par‐
ticular this can occur during a read or on a slow device (such as a
terminal; but not a file) and during a
The value of is the previous (or initial) value of func for the partic‐
ular signal.
After a or the child inherits all signals. The system call resets all
caught signals to the default action; ignored signals remain ignored.
VAX-11 Notes
The handler routine can be declared:
handler(sig, code, scp)
Here sig is the signal number, into which the hardware faults and traps
are mapped as defined below. Code is a parameter which is either a
constant as given below or, for compatibility mode faults, the code
provided by the hardware. The scp is a pointer to the struct sigcon‐
text used by the system to restore the process context from before the
signal. Compatibility mode faults are distinguished from the other
SIGILL traps by having PSL_CM set in the psl.
The following defines the mapping of hardware traps to signals and
codes. All of these symbols are defined in < signal.h >:
Hardware condition Signal Code
Arithmetic traps:
Integer overflow SIGFPE FPE_INTOVF_TRAP
Integer division by zero SIGFPE FPE_INTDIV_TRAP
Floating overflow trap SIGFPE FPE_FLTOVF_TRAP
Floating/decimal division by zero SIGFPE FPE_FLTDIV_TRAP
Floating underflow trap SIGFPE FPE_FLTUND_TRAP
Decimal overflow trap SIGFPE FPE_DECOVF_TRAP
Subscript-range SIGFPE FPE_SUBRNG_TRAP
Floating overflow fault SIGFPE FPE_FLTOVF_FAULT
Floating divide by zero fault SIGFPE FPE_FLTDIV_FAULT
Floating underflow fault SIGFPE FPE_FLTUND_FAULT
Length access control SIGSEGV fault virtual addr
Protection violation SIGBUS fault virtual addr
Reserved instruction SIGILL ILL_PRIVIN_FAULT
Customer-reserved instr. SIGEMT
Reserved operand SIGILL ILL_RESOP_FAULT
Reserved addressing SIGILL ILL_RESAD_FAULT
Trace pending SIGTRAP
Bpt instruction SIGTRAP
Compatibility-mode SIGILL hrdwr suppl'd code
Chme SIGSEGV
Chms SIGSEGV
Chmu SIGSEGV
Return Values
The previous action is returned on a successful call. Otherwise, -1 is
returned and errno is set to indicate the error.
Diagnostics
The subroutine will fail and no action will take place if one of the
following occur:
[EINVAL] The sig is not a valid signal number.
[EINVAL] An attempt is made to ignore or supply a handler for
SIGKILL or SIGSTOP.
Environment
When your program is compiled using the System V environment the han‐
dler function does NOT remain installed after the signal has been
delivered.
Also, when a signal which is to be caught occurs during a read(),
write(), or ioctl() to a slow device (like a terminal, but not a file);
or during a pause(); or wait() that does not return immediately, the
signal handler function is executed, and then the interrupted system
call may return a -1 to the calling process with errno set to EINTR.
See Alsokill(1), kill(2), ptrace(2), sigblock(2), sigpause(2), sigsetmask(2),
sigstack(2), sigvec(2), setjmp(3), tty(4)
VAX signal(3)