SIGNAL(3B) SIGNAL(3B)
signal - simplified software signal facilities (4.3BSD)
#include <signal.h>
int (*signal(int sig, int (*func)(int, ...)))(int, ...);
To use any of the BSD signal routines (kill(3B), killpg(3B),
sigblock(3B), signal(3B), sigpause(3B), sigsetmask(3B), sigstack(2B),
sigvec(3B)) you must either
1) #define _BSD_SIGNALS or _BSD_COMPAT before including <signal.h>, or
2) specify one of them in the compile command or makefile:
cc -D_BSD_SIGNALS -o prog prog.c
signal is a simplified interface to the more general sigvec(3B) 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 background
(see termio(7)). Signals are optionally generated when a process resumes
after being stopped, when the status of child processes 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 signal call allows signals either to be ignored or
to cause an interrupt to a specified location.
For a list of valid signal numbers and a general description of the
signal mechanism, please see signal(5).
If func is SIG_DFL, the default action for signal sig is reinstated. 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 the System V signal
routine, the handler func remains installed after a signal has been
delivered.
SIGKILL will immediately terminate a process, regardless of its state.
Processes which are stopped via job control (typically <Ctrl>-Z) will not
act upon any delivered signals other than SIGKILL until the job is
restarted. Processes which are blocked via a blockproc system call will
Page 1
SIGNAL(3B) SIGNAL(3B)
unblock if they receive a signal which is fatal (i.e., a non-job-control
signal which they are NOT catching), but will still be stopped if the job
of which they are a part is stopped. Only upon restart will they die.
Any non-fatal signals received by a blocked process will NOT cause the
process to be unblocked (a call to unblockproc(2) or unblockprocall(2) is
necessary).
The value of signal is the previous (or initial) value of func for the
particular signal.
After a fork(2) the child inherits all handlers and signal masks, but not
the set of pending signals.
The exec(2) routines reset all caught signals to the default action;
ignored signals remain ignored, the blocked signal mask is unchanged and
pending signals remain pending.
The previous action is returned on a successful call. Otherwise, -1 is
returned and errno is set to indicate the error.
signal will fail and no action will take place if one of the following
occur:
[EINVAL] Sig is not a valid signal number.
[EINVAL] An attempt is made to ignore or supply a handler for
SIGKILL or SIGSTOP.
[EINVAL] An attempt is made to ignore SIGCONT (by default SIGCONT
is ignored).
kill(3B), sigvec(3B), sigblock(3B), sigsetmask(3B), sigpause(3B),
setjmp(3), blockproc(2), signal(5).
CAVEATS (IRIX)
4.2BSD attempts to restart system calls which are interrupted by signal
receipt; 4.3BSD gives the programmer a choice of restart or failedreturn-with-error
via the SV_INTERRUPT flag in sigvec or use of the
siginterrupt library routine. IRIX provides only the fail-with-error
option. The affected system calls are read(2), write(2), open(2),
ioctl(2), and wait(2). Refer to the sigset(2) man page for a more
detailed description of the behavior.
Because 4.3BSD and System V both have signal system calls, programs using
4.3BSD's version are actually executing BSDsignal. This is transparent
to the programmer except when attempting to set breakpoints in dbx; the
Page 2
SIGNAL(3B) SIGNAL(3B)
breakpoint must be set at BSDsignal.
WARNING (IRIX)
The 4.3BSD and System V signal facilities have different semantics.
Using both facilities in the same program is strongly discouraged and
will result in unpredictable behavior.
PPPPaaaaggggeeee 3333 [ Back ]
|