'\" te .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright (c) 1980 Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution. .TH SIGVEC 3UCB "Oct 30, 2007" .SH NAME sigvec \- software signal facilities .SH SYNOPSIS .LP .nf \fB/usr/ucb/cc\fR [ \fIflag\fR \&.\|.\|. ] \fIfile\fR\&.\|.\|. #include \fBint\fR \fBsigvec\fR(\fIsig\fR, \fInvec\fR, \fIovec\fR) \fBint\fR \fIsig\fR; \fBstruct sigvec *\fR\fInvec\fR, \fB*\fR\fIovec\fR; .fi .SH DESCRIPTION .sp .LP 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 \fIhandler\fR to which a signal is delivered, or specify that a signal is to be \fIblocked\fR or \fIignored\fR. A process may also specify that a default action is to be taken by the system when a signal occurs. Normally, signal handlers execute on the current stack of the process. This may be changed, on a per-handler basis, so that signals are taken on a special \fIsignal stack\fR. .sp .LP All signals have the same \fIpriority\fR. Signal routines execute with the signal that caused their invocation to be \fIblocked\fR, but other signals may yet occur. A global \fIsignal mask\fR 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 \fBsigblock()\fR or \fBsigsetmask()\fR call, or when a signal is delivered to the process. .sp .LP A process may also specify a set of \fIflags\fR for a signal that affect the delivery of that signal. .sp .LP 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 \fIblocked\fR 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. .sp .LP 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 \fBsigblock()\fR or \fBsigsetmask()\fR call is made). This mask is formed by taking the current signal mask, adding the signal to be delivered, and \fBOR\fRing in the signal mask associated with the handler to be invoked. .sp .LP The action to be taken when the signal is delivered is specified by a \fBsigvec()\fR structure, which includes the following members: .sp .in +2 .nf void (*sv_handler)(\|); /* signal handler */ int sv_mask; /* signal mask to apply */ int sv_flags; /* see signal options */ #define SV_ONSTACK /* take signal on signal stack */ #define SV_INTERRUPT /* do not restart system on signal return */ #define SV_RESETHAND /* reset handler to SIG_DFL when signal taken*/ .fi .in -2 .sp .LP If the \fBSV_ONSTACK\fR bit is set in the flags for that signal, the system will deliver the signal to the process on the signal stack specified with \fBsigstack\fR(3UCB) rather than delivering the signal on the current stack. .sp .LP If \fInvec\fR is not a \fINULL\fR pointer, \fBsigvec()\fR assigns the handler specified by \fBsv_handler()\fR, the mask specified by \fBsv_mask()\fR, and the flags specified by \fBsv_flags()\fR to the specified signal. If \fInvec\fR is a \fINULL\fR pointer, \fBsigvec()\fR does not change the handler, mask, or flags for the specified signal. .sp .LP The mask specified in \fInvec\fR is not allowed to block \fBSIGKILL\fR, \fBSIGSTOP\fR, or \fBSIGCONT\fR. The system enforces this restriction silently. .sp .LP If \fIovec\fR is not a \fINULL\fR pointer, the handler, mask, and flags in effect for the signal before the call to \fBsigvec()\fR are returned to the user. A call to \fBsigvec()\fR with \fInvec\fR a \fINULL\fR pointer and \fIovec\fR not a \fINULL\fR pointer can be used to determine the handling information currently in effect for a signal without changing that information. .sp .LP The following is a list of all signals with names as in the include file \fB\fR: .sp .ne 2 .na \fB\fBSIGHUP\fR\fR .ad .RS 13n hangup .RE .sp .ne 2 .na \fB\fBSIGINT\fR\fR .ad .RS 13n interrupt .RE .sp .ne 2 .na \fB\fBSIGQUIT\fR*\fR .ad .RS 13n quit .RE .sp .ne 2 .na \fB\fBSIGILL\fR*\fR .ad .RS 13n illegal instruction .RE .sp .ne 2 .na \fB\fBSIGTRAP\fR*\fR .ad .RS 13n trace trap .RE .sp .ne 2 .na \fB\fBSIGABRT\fR*\fR .ad .RS 13n abort (generated by \fBabort\fR(3C) routine) .RE .sp .ne 2 .na \fB\fBSIGEMT\fR*\fR .ad .RS 13n emulator trap .RE .sp .ne 2 .na \fB\fBSIGFPE\fR*\fR .ad .RS 13n arithmetic exception .RE .sp .ne 2 .na \fB\fBSIGKILL\fR\fR .ad .RS 13n kill (cannot be caught, blocked, or ignored) .RE .sp .ne 2 .na \fB\fBSIGBUS\fR*\fR .ad .RS 13n bus error .RE .sp .ne 2 .na \fB\fBSIGSEGV\fR*\fR .ad .RS 13n segmentation violation .RE .sp .ne 2 .na \fB\fBSIGSYS\fR*\fR .ad .RS 13n bad argument to function .RE .sp .ne 2 .na \fB\fBSIGPIPE\fR\fR .ad .RS 13n write on a pipe or other socket with no one to read it .RE .sp .ne 2 .na \fB\fBSIGALRM\fR\fR .ad .RS 13n alarm clock .RE .sp .ne 2 .na \fB\fBSIGTERM\fR\fR .ad .RS 13n software termination signal .RE .sp .ne 2 .na \fB\fBSIGURG\fR*\fR .ad .RS 13n urgent condition present on socket .RE .sp .ne 2 .na \fB\fBSIGSTOP\fR**\fR .ad .RS 13n stop (cannot be caught, blocked, or ignored) .RE .sp .ne 2 .na \fB\fBSIGTSTP\fR**\fR .ad .RS 13n stop signal generated from keyboard .RE .sp .ne 2 .na \fB\fBSIGCONT\fR*\fR .ad .RS 13n continue after stop (cannot be blocked) .RE .sp .ne 2 .na \fB\fBSIGCHLD\fR*\fR .ad .RS 13n child status has changed .RE .sp .ne 2 .na \fB\fBSIGTTIN\fR**\fR .ad .RS 13n background read attempted from control terminal .RE .sp .ne 2 .na \fB\fBSIGTTOU\fR**\fR .ad .RS 13n background write attempted to control terminal .RE .sp .ne 2 .na \fB\fBSIGIO\fR*\fR .ad .RS 13n I/O is possible on a descriptor (see \fBfcntl\fR(2)) .RE .sp .ne 2 .na \fB\fBSIGXCPU\fR\fR .ad .RS 13n cpu time limit exceeded (see \fBgetrlimit\fR(2)) .RE .sp .ne 2 .na \fB\fBSIGXFSZ\fR\fR .ad .RS 13n file size limit exceeded (see \fBgetrlimit\fR(2)) .RE .sp .ne 2 .na \fB\fBSIGVTALRM\fR\fR .ad .RS 13n virtual time alarm; see \fBsetitimer()\fR on \fBgetitimer\fR(2) .RE .sp .ne 2 .na \fB\fBSIGPROF\fR\fR .ad .RS 13n profiling timer alarm; see \fBsetitimer()\fR on \fBgetitimer\fR(2) .RE .sp .ne 2 .na \fB\fBSIGWINCH\fR*\fR .ad .RS 13n window changed (see \fBtermio\fR(7I)) .RE .sp .ne 2 .na \fB\fBSIGLOST\fR\fR .ad .RS 13n resource lost (see \fBlockd\fR(1M)) .RE .sp .ne 2 .na \fB\fBSIGUSR1\fR\fR .ad .RS 13n user-defined signal 1 .RE .sp .ne 2 .na \fB\fBSIGUSR2\fR\fR .ad .RS 13n user-defined signal 2 .RE .sp .LP The starred signals in the list above cause a core image if not caught or ignored. .sp .LP Once a signal handler is installed, it remains installed until another \fBsigvec()\fR call is made, or an \fBexecve\fR(2) is performed, unless the \fBSV_RESETHAND\fR bit is set in the flags for that signal. In that case, the value of the handler for the caught signal will be set to \fBSIG_DFL\fR before entering the signal-catching function, unless the signal is \fBSIGILL\fR, \fBSIGPWR\fR, or \fBSIGTRAP\fR. Also, if this bit is set, the bit for that signal in the signal mask will not be set; unless the signal mask associated with that signal blocks that signal, further occurrences of that signal will not be blocked. The \fBSV_RESETHAND\fR flag is not available in 4.2BSD, hence it should not be used if backward compatibility is needed. .sp .LP The default action for a signal may be reinstated by setting the signal's handler to \fBSIG_DFL\fR; this default is termination except for signals marked with * or **. Signals marked with * are discarded if the action is \fBSIG_DFL\fR; signals marked with ** cause the process to stop. If the process is terminated, a "core image" will be made in the current working directory of the receiving process if the signal is one for which an asterisk appears in the above list (see \fBcore\fR(4)). .sp .LP If the handler for that signal is \fBSIG_IGN\fR, the signal is subsequently ignored, and pending instances of the signal are discarded. .sp .LP If a caught signal occurs during certain functions, the call is normally restarted. The call can be forced to terminate prematurely with an \fBEINTR\fR error return by setting the \fBSV_INTERRUPT\fR bit in the flags for that signal. The \fBSV_INTERRUPT\fR flag is not available in 4.2BSD, hence it should not be used if backward compatibility is needed. The affected functions are \fBread\fR(2) or \fBwrite\fR(2) on a slow device (such as a terminal or pipe or other socket, but not a file) and during a \fBwait\fR(3C). .sp .LP After a \fBfork\fR(2) or \fBvfork\fR(2) the child inherits all signals, the signal mask, the signal stack, and the restart/interrupt and reset-signal-handler flags. .sp .LP The \fBexecve\fR(2) call resets all caught signals to default action and resets all signals to be caught on the user stack. Ignored signals remain ignored; the signal mask remains the same; signals that interrupt functions continue to do so. .sp .LP The accuracy of \fIaddr\fR is machine dependent. For example, certain machines may supply an address that is on the same page as the address that caused the fault. If an appropriate \fIaddr\fR cannot be computed it will be set to \fBSIG_NOADDR\fR. .SH RETURN VALUES .sp .LP A \fB0\fR value indicates that the call succeeded. A \fB\(mi1\fR return value indicates that an error occurred and \fBerrno\fR is set to indicate the reason. .SH ERRORS .sp .LP \fBsigvec()\fR will fail and no new signal handler will be installed if one of the following occurs: .sp .ne 2 .na \fB\fBEFAULT\fR\fR .ad .RS 10n Either \fInvec\fR or \fIovec\fR is not a \fINULL\fR pointer and points to memory that is not a valid part of the process address space. .RE .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 10n \fIsig\fR is not a valid signal number or is \fBSIGKILL\fR or \fBSIGSTOP\fR. .RE .SH SEE ALSO .sp .LP \fBIntro\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), \fBfork\fR(2), \fBgetitimer\fR(2), \fBgetrlimit\fR(2), \fBioctl\fR(2), \fBkill\fR(2), \fBread\fR(2), \fBumask\fR(2), \fBvfork\fR(2), \fBwrite\fR(2), \fBptrace\fR(3C), \fBsetjmp\fR(3C) \fBsigblock\fR(3UCB), \fBsignal\fR(3C), \fBsignal\fR(3UCB), \fBsigstack\fR(3UCB), \fBwait\fR(3C), \fBwait\fR(3UCB), \fBcore\fR(4), \fBstreamio\fR(7I), \fBtermio\fR(7I) .SH NOTES .sp .LP Use of these interfaces should be restricted to only applications written on BSD platforms. Use of these interfaces with any of the system libraries or in multi-thread applications is unsupported. .sp .LP \fBSIGPOLL\fR is a synonym for \fBSIGIO\fR. A \fBSIGIO\fR will be issued when a file descriptor corresponding to a \fBSTREAMS\fR (see \fBIntro\fR(2)) file has a "selectable" event pending. Unless that descriptor has been put into asynchronous mode (see \fBfcntl\fR(2)), a process may specifically request that this signal be sent using the \fBI_SETSIG\fR \fBioctl\fR(2) call (see \fBstreamio\fR(7I)). Otherwise, the process will never receive \fBSIGPOLLs0\fR. .sp .LP The handler routine can be declared: .sp .in +2 .nf void handler(int sig, int code, struct sigcontext *scp, char *addr); .fi .in -2 .sp .LP Here \fIsig\fR is the signal number; \fIcode\fR is a parameter of certain signals that provides additional detail; \fIscp\fR is a pointer to the \fBsigcontext\fR structure (defined in \fBsignal.h\fR), used to restore the context from before the signal; and \fIaddr\fR is additional address information. .sp .LP The signals \fBSIGKILL\fR, \fBSIGSTOP\fR, and \fBSIGCONT\fR cannot be ignored.