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