SIGVEC(3B) SIGVEC(3B)
sigvec - 4.3BSD software signal facilities
#include <signal.h>
struct sigvec {
int (*sv_handler)(int, int);
int sv_mask;
int sv_flags;
};
int sigvec(int sig, struct sigvec *vec, struct sigvec *ovec);
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
sigvec specifies and reports on the way individual signals are to be
handled in the calling process. If vec is non-zero, it alters the way
the signal will be treated - default behavior, ignored, or handled via a
routine - and the signal mask to be used when delivering the signal if a
handler is installed. If ovec is non-zero, the previous handling
information for the signal is returned to the user. In this way (a NULL
vec and a non-NULL ovec) the user can inquire as to the current handling
of a signal without changing it. If both vec and ovec are NULL, sigvec
will return -1 and set errno to EINVAL if sig is an invalid signal (else
0), allowing an application to dynamically determine the set of signals
supported by the system.
The system defines a set of signals that may be delivered to a process.
Signal delivery resembles the occurrence of a hardware interrupt: the
signal is blocked from further occurrence, the current process context is
saved, and a new one is built. A process may specify a handler to which
a signal is delivered, or specify that a signal is to be blocked or
ignored. A process may also specify that a default action is to be taken
by the system when a signal occurs.
All signals have the same priority. Signal routines execute with the
signal that caused their invocation blocked, but other signals may yet
occur. A global signal mask defines the set of signals currently blocked
from delivery to a process. The signal mask for a process is initialized
from that of its parent (normally 0). It may be changed with a
sigbloc
call, or when a signal is delivered to the
Page 1
SIGVEC(3B) SIGVEC(3B)
process.
When a signal condition arises for a process, the signal is added to a
set of signals pending for the process. If the signal is not currently
blocked by the process then it is delivered to the process. When a
signal is delivered, the current state of the process is saved, a new
signal mask is calculated (as described below), and the signal handler is
invoked. The call to the handler is arranged so that if the signal
handling routine returns normally the process will resume execution in
the context from before the signal's delivery. If the process wishes to
resume in a different context, then it must arrange to restore the
previous context itself.
When a signal is delivered to a process a new signal mask is installed
for the duration of the process' signal handler (or until a sigblock or
sigsetmask call is made). This mask is formed by taking the current
signal mask, adding the signal to be delivered, and or'ing in the signal
mask associated with the handler to be invoked.
Sigvec assigns a handler for a specific signal. If vec is non-zero, it
specifies a handler routine and mask to be used when delivering the
specified signal. Further, if the SV_ONSTACK bit is set in sv_flags, the
system will deliver the signal to the process on a signal stack,
specified with sigstack(2b).
For a list of valid signal numbers and a general description of the
signal mechanism, please see signal(5).
Once a signal handler is installed, it remains installed until another
sigvec call is made, or an execve(2) is performed. The default action
for a signal may be reinstated by setting sv_handler to SIG_DFL; this
default is termination with a core image for signals marked [1]. If
sv_handler is SIG_IGN the signal is subsequently ignored, and pending
instances of the signal are discarded.
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(2) system call
will unblock if they receive a signal which is fatal (i.e., a non-jobcontrol
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).
After a fork(2) the child inherits all handlers, the signal stack and the
signal masks, but not the set of the pending signals.
The exec(2) routines reset all caught signals to default action , clear
all handler masks and reset all signals to be caught on the user stack.
Ignored signals remain ignored; the blocked signal mask is unchanged and
Page 2
SIGVEC(3B) SIGVEC(3B)
pending signals remain pending.
The mask specified in vec is not allowed to block SIGKILL, SIGSTOP, or
SIGCONT. This is enforced silently by the system.
A 0 value indicated that the call succeeded. A -1 return value indicates
an error occurred and errno is set to indicate the reason.
sigvec is a library routine (executing in user space): if either vec or
ovec points to memory that is not a valid part of the process address
space, the process will receive a memory fault (SIGSEGV) signal and
terminate (unless it has installed a handler for SIGSEGV). If the
invalid pointer is the result of using a REFERENCE instead of a POINTER,
the compiler will issue a warning.
sigvec will fail and no new signal handler will be installed if one of
the following occurs:
[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), sigblock(3B), sigsetmask(3B), sigpause(3B), sigvec(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 more a
detailed description of the behavior.
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 ]
|