SIGNAL(2) SIGNAL(2)
NAME
signal - specify what to do upon receipt of a signal
SYNOPSIS
#include <signal.h>
void (*signal (sig, func))()
int sig;
void (*func)();
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
SIGKILLorCIGSTOP:
SIGHUP 01 hangup
SIGINT 02 interrupt
SIGQUIT 03[1] quit
SIGILL 04[1] illegal instruction (not reset when caught)
SIGTRAP 05[1] trace trap (not reset when caught)
SIGIOT 06[1] IOT instruction
SIGEMT 07[2] EMT instruction
SIGFPE 08[1] floating point exception
SIGKILL 09 kill (cannot be caught, blocked, or ignored)
SIGBUS 10[1] bus error
SIGSEGV 11[1] segmentation violation
SIGSYS 12[1] 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
SIGUSR1 16 user-defined signal 1
SIGUSR2 17 user-defined signal 2
SIGCLD 18[2] death of a child
SIGPWR 19[2] power fail
Page 1 May 1989
SIGNAL(2) SIGNAL(2)
SIGWINCH 20 window size change
SIGTSTP 21[4] stop signal generated from keyboard
SIGPOLL 22[3] selectable event pending
SIGSTOP 23[4] stop (cannot be caught, blocked, or ignored)
SIGCONT 25[5] continue after stop (cannot be blocked)
SIGTTIN 26[4] background read attempted from control terminal
SIGTTON 27[4] background write attempted to control terminal
SIGURG 33 urgent condition present on socket
SIGVTALARM 37 virtual time alarm [see setitimer (2)]
SIGPROF 38 profiling timer alarm [see setitimer(2)]
Func is assigned one of three values: SIGDFL, SIGIGN, or
a function address. SIGDFL, and SIGIGN, are defined in
the include file signal.h. Each is a macro that expands to
a constant expression of type pointer to function returning
void, and has a unique value that matches no declarable
function.
The actions prescribed by the values of func are as follows:
SIGDFL - terminate process upon receipt of a signal with
the exception of those noted below.
Upon receipt of the signal sig, the receiving
process is to be terminated with all of the
consequences outlined in exit(2). See NOTES [1]
below.[4], [5] below.
SIGIGN - ignore signal
The signal sig is to be ignored.
Note: the signals SIGKILL and SIGSTOP 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 only argument to the signal-catching
function. Additional arguments are passed to the
signal-catching function for hardware-generated
Page 2 May 1989
SIGNAL(2) SIGNAL(2)
signals. Before entering the signal-catching
function, the value of func for the caught signal
will be set to SIGDFL unless the signal is
SIGILL, SIGTRAP, or SIGPWR.
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 a
read(2), a write(2), an open(2), or an ioctl(2)
system call on a slow device (like a terminal; but
not a file), during a pause(2) system call, or
during a wait(2) 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 and then the interrupted
system call may return a -1 to the calling process
with errno set to EINTR.
signal will not catch an invalid function
argument, func, and results are undefined when an
attempt is made to execute the function at the bad
address.
Note: The signal SIGKILL cannot be caught.
A call to signal cancels a pending signal sig except for a
pending SIGKILL or SIGSTOP signal.
signal will fail if sig is an illegal signal number,
including SIGKILL or SIGSTOP. [EINVAL]
NOTES
[1] If SIGDFL is assigned for these signals, in addition to
the process being terminated, a ``core image'' will be
constructed in the current working directory of the
process, if the following conditions are met:
The effective user ID and the real user ID of
Page 3 May 1989
SIGNAL(2) SIGNAL(2)
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
[2] For the signals SIGCLD and SIGPWR, func is assigned one
of three values: SIGDFL, SIGIGN, or a function
address. The actions prescribed by these values are:
SIGDFL - ignore signal
The signal is to be ignored.
SIGIGN - 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 with one
exception: while the process is executing the
signal-catching function, any received SIGCLD
signals will be ignored. (This is the default
action.)
Page 4 May 1989
SIGNAL(2) SIGNAL(2)
In addition, SIGCLD affects the wait, and exit system
calls as follows:
wait If the func value of SIGCLD is set to SIGIGN
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 SIGIGN, 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 proceeding
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.
[3] SIGPOLL is issued when a file descriptor corresponding
to a STREAMS [see intro(2)] file has a "selectable"
event pending. A process must specifically request that
this signal be sent using the I_SETSIG ioctl call.
Otherwise, the process will never receive SIGPOLL.
[4] For these signals, if func is set to SIGDFL, the
execution of the process will be suspended and will
remain so until it receives a SIGCONT signal.
[5] The SIGCONT signal will always restart a stopped process
regardless of what func has been set to. If fund is set
to SIGDFL, the signal will be ignored after the process
has been restarted, if necessary.
SEE ALSO
intro(2), kill(2), pause(2), ptrace(2), wait(2), setjmp(3C),
sigset(2), sigaction(2).
kill(1) in the User's Reference Manual.
Page 5 May 1989
SIGNAL(2) SIGNAL(2)
DIAGNOSTICS
Upon successful completion, signal returns the previous
value of func for the specified signal sig. Otherwise, a
value of SIG_ERR is returned and errno is set to indicate
the error. SIG_ERR is defined in the include file signal.h.
Page 6 May 1989