1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)sigvec.2 8.2 (Berkeley) 4/19/94 33.\" $FreeBSD$ 34.\" 35.Dd April 19, 1994 36.Dt SIGVEC 2 37.Os BSD 4 38.Sh NAME 39.Nm sigvec 40.Nd software signal facilities 41.Sh SYNOPSIS 42.Fd #include <signal.h> 43.Bd -literal 44struct sigvec { 45 void (*sv_handler)(); 46 int sv_mask; 47 int sv_flags; 48}; 49.Ed 50.Ft int 51.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec" 52.Sh DESCRIPTION 53.Bf -symbolic 54This interface is made obsolete by sigaction(2). 55.Ef 56.Pp 57The system defines a set of signals that may be delivered to a process. 58Signal delivery resembles the occurrence of a hardware interrupt: 59the signal is blocked from further occurrence, the current process 60context is saved, and a new one is built. A process may specify a 61.Em handler 62to which a signal is delivered, or specify that a signal is to be 63.Em blocked 64or 65.Em ignored . 66A process may also specify that a default action is to be taken 67by the system when a signal occurs. 68Normally, signal handlers execute on the current stack 69of the process. This may be changed, on a per-handler basis, 70so that signals are taken on a special 71.Em "signal stack" . 72.Pp 73All signals have the same 74.Em priority . 75Signal routines execute with the signal that caused their 76invocation 77.Em blocked , 78but other signals may yet occur. 79A global 80.Em "signal mask" 81defines the set of signals currently blocked from delivery 82to a process. The signal mask for a process is initialized 83from that of its parent (normally 0). It 84may be changed with a 85.Xr sigblock 2 86or 87.Xr sigsetmask 2 88call, or when a signal is delivered to the process. 89.Pp 90When a signal 91condition arises for a process, the signal is added to a set of 92signals pending for the process. If the signal is not currently 93.Em blocked 94by the process then it is delivered to the process. When a signal 95is delivered, the current state of the process is saved, 96a new signal mask is calculated (as described below), 97and the signal handler is invoked. The call to the handler 98is arranged so that if the signal handling routine returns 99normally the process will resume execution in the context 100from before the signal's delivery. 101If the process wishes to resume in a different context, then it 102must arrange to restore the previous context itself. 103.Pp 104When a signal is delivered to a process a new signal mask is 105installed for the duration of the process' signal handler 106(or until a 107.Xr sigblock 2 108or 109.Xr sigsetmask 2 110call is made). 111This mask is formed by taking the current signal mask, 112adding the signal to be delivered, and 113.Em or Ns 'ing 114in the signal mask associated with the handler to be invoked. 115.Pp 116.Fn Sigvec 117assigns a handler for a specific signal. If 118.Fa vec 119is non-zero, it 120specifies a handler routine and mask 121to be used when delivering the specified signal. 122Further, if the 123.Dv SV_ONSTACK 124bit is set in 125.Fa sv_flags , 126the system will deliver the signal to the process on a 127.Em "signal stack" , 128specified with 129.Xr sigaltstack 2 . 130If 131.Fa ovec 132is non-zero, the previous handling information for the signal 133is returned to the user. 134.Pp 135The following is a list of all signals 136with names as in the include file 137.Aq Pa signal.h : 138.Bl -column SIGVTALARMXX "create core imagexxx" 139.It Sy " NAME " " Default Action " " Description" 140.It Dv SIGHUP No " terminate process" " terminal line hangup" 141.It Dv SIGINT No " terminate process" " interrupt program" 142.It Dv SIGQUIT No " create core image" " quit program" 143.It Dv SIGILL No " create core image" " illegal instruction" 144.It Dv SIGTRAP No " create core image" " trace trap" 145.It Dv SIGABRT No " create core image" Xr abort 3 146call (formerly 147.Dv SIGIOT ) 148.It Dv SIGEMT No " create core image" " emulate instruction executed" 149.It Dv SIGFPE No " create core image" " floating-point exception" 150.It Dv SIGKILL No " terminate process" " kill program" 151.It Dv SIGBUS No " create core image" " bus error" 152.It Dv SIGSEGV No " create core image" " segmentation violation" 153.It Dv SIGSYS No " create core image" " non-existent system call invoked" 154.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 155.It Dv SIGALRM No " terminate process" " real-time timer expired" 156.It Dv SIGTERM No " terminate process" " software termination signal" 157.It Dv SIGURG No " discard signal" " urgent condition present on socket" 158.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 159.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 160.It Dv SIGCONT No " discard signal" " continue after stop" 161.It Dv SIGCHLD No " discard signal" " child status has changed" 162.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 163.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 164.It Dv SIGIO No " discard signal" Tn " I/O" 165is possible on a descriptor (see 166.Xr fcntl 2 ) 167.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 168.Xr setrlimit 2 ) 169.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 170.Xr setrlimit 2 ) 171.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 172.Xr setitimer 2 ) 173.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 174.Xr setitimer 2 ) 175.It Dv SIGWINCH No " discard signal" " Window size change" 176.It Dv SIGINFO No " discard signal" " status request from keyboard" 177.It Dv SIGUSR1 No " terminate process" " User defined signal 1" 178.It Dv SIGUSR2 No " terminate process" " User defined signal 2" 179.El 180.Pp 181Once a signal handler is installed, it remains installed 182until another 183.Fn sigvec 184call is made, or an 185.Xr execve 2 186is performed. 187A signal-specific default action may be reset by 188setting 189.Fa sv_handler 190to 191.Dv SIG_DFL . 192The defaults are process termination, possibly with core dump; 193no action; stopping the process; or continuing the process. 194See the above signal list for each signal's default action. 195If 196.Fa sv_handler 197is 198.Dv SIG_IGN 199current and pending instances 200of the signal are ignored and discarded. 201.Pp 202If a signal is caught during the system calls listed below, 203the call is normally restarted. 204The call can be forced to terminate prematurely with an 205.Dv EINTR 206error return by setting the 207.Dv SV_INTERRUPT 208bit in 209.Fa sv_flags . 210The affected system calls include 211.Xr read 2 , 212.Xr write 2 , 213.Xr sendto 2 , 214.Xr recvfrom 2 , 215.Xr sendmsg 2 216and 217.Xr recvmsg 2 218on a communications channel or a slow device (such as a terminal, 219but not a regular file) 220and during a 221.Xr wait 2 222or 223.Xr ioctl 2 . 224However, calls that have already committed are not restarted, 225but instead return a partial success (for example, a short read count). 226.Pp 227After a 228.Xr fork 2 229or 230.Xr vfork 2 231all signals, the signal mask, the signal stack, 232and the restart/interrupt flags are inherited by the child. 233.Pp 234.Xr Execve 2 235reinstates the default 236action for all signals which were caught and 237resets all signals to be caught on the user stack. 238Ignored signals remain ignored; 239the signal mask remains the same; 240signals that interrupt system calls continue to do so. 241.Sh NOTES 242The mask specified in 243.Fa vec 244is not allowed to block 245.Dv SIGKILL 246or 247.Dv SIGSTOP . 248This is done silently by the system. 249.Pp 250The 251.Dv SV_INTERRUPT 252flag is not available in 253.Bx 4.2 , 254hence it should not be used if backward compatibility is needed. 255.Sh RETURN VALUES 256A 0 value indicated that the call succeeded. A \-1 return value 257indicates an error occurred and 258.Va errno 259is set to indicated the reason. 260.Sh ERRORS 261.Fn Sigvec 262will fail and no new signal handler will be installed if one 263of the following occurs: 264.Bl -tag -width [EINVAL] 265.It Bq Er EFAULT 266Either 267.Fa vec 268or 269.Fa ovec 270points to memory that is not a valid part of the process 271address space. 272.It Bq Er EINVAL 273.Fa Sig 274is not a valid signal number. 275.It Bq Er EINVAL 276An attempt is made to ignore or supply a handler for 277.Dv SIGKILL 278or 279.Dv SIGSTOP . 280.El 281.Sh SEE ALSO 282.Xr kill 1 , 283.Xr kill 2 , 284.Xr ptrace 2 , 285.Xr sigaction 2 , 286.Xr sigaltstack 2 , 287.Xr sigblock 2 , 288.Xr sigpause 2 , 289.Xr sigprocmask 2 , 290.Xr sigsetmask 2 , 291.Xr sigsuspend 2 , 292.Xr setjmp 3 , 293.Xr siginterrupt 3 , 294.Xr signal 3 , 295.Xr sigsetops 3 , 296.Xr tty 4 297.Sh EXAMPLE 298On the 299.Tn VAX\-11 300The handler routine can be declared: 301.Bd -literal -offset indent 302void handler(sig, code, scp) 303int sig, code; 304struct sigcontext *scp; 305.Ed 306.Pp 307Here 308.Fa sig 309is the signal number, into which the hardware faults and traps are 310mapped as defined below. 311.Fa Code 312is a parameter that is either a constant 313as given below or, for compatibility mode faults, the code provided by 314the hardware (Compatibility mode faults are distinguished from the 315other 316.Dv SIGILL 317traps by having 318.Dv PSL_CM 319set in the psl). 320.Fa Scp 321is a pointer to the 322.Fa sigcontext 323structure (defined in 324.Aq Pa signal.h ) , 325used to restore the context from before the signal. 326.Sh BUGS 327This manual page is still confusing. 328