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