1*48352Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 2*48352Scael.\" All rights reserved. 320132Smckusick.\" 4*48352Scael.\" %sccs.include.redist.man% 520132Smckusick.\" 6*48352Scael.\" @(#)signal.3 6.6 (Berkeley) 04/19/91 7*48352Scael.\" 8*48352Scael.Dd 9*48352Scael.Dt SIGNAL 3 10*48352Scael.Os BSD 4 11*48352Scael.Sh NAME 12*48352Scael.Nm signal 13*48352Scael.Nd simplified software signal facilities 14*48352Scael.Sh SYNOPSIS 15*48352Scael.Fd #include <signal.h> 16*48352Scael.Ft void 17*48352Scael.\" can not do this with .Fn yet 18*48352Scael\*(fN*signal\*(lp\*(fAsig\fR, \*(fAfunc\*(rp\|\*(lp\|\*(rp\fR 19*48352Scael.br 20*48352Scael.Ft void 21*48352Scael\*(fN*func\*(rp\*(lp\|\*(rp\fR 22*48352Scael.Sh DESCRIPTION 23*48352ScaelThis 24*48352Scael.Fn signal 25*48352Scaelfacility 2620133Smckusickis a simplified interface to the more general 27*48352Scael.Xr sigaction 2 2820133Smckusickfacility. 29*48352Scael.Pp 30*48352ScaelSignals allow the manipulation of a process from outside its 31*48352Scaeldomain as well as allowing the process to manipulate itself or 32*48352Scaelcopies of itself (children). There are two general types of signals: 33*48352Scaelthose that cause termination of a process and those that do not. 34*48352ScaelSignals which cause termination of a program might result from 35*48352Scaelan irrecoverable error or might be the result of a user at a terminal 36*48352Scaeltyping the `interrupt' character. 37*48352ScaelSignals are used when a process is stopped because it wishes to access 3820133Smckusickits control terminal while in the background (see 39*48352Scael.Xr tty 4 ) . 4020133SmckusickSignals are optionally generated 4120133Smckusickwhen a process resumes after being stopped, 4220133Smckusickwhen the status of child processes changes, 4320133Smckusickor when input is ready at the control terminal. 44*48352ScaelMost signals result in the termination of the process receiving them 45*48352Scaelif no action 4620133Smckusickis taken; some signals instead cause the process receiving them 4720133Smckusickto be stopped, or are simply discarded if the process has not 4820133Smckusickrequested otherwise. 49*48352ScaelExcept for the 50*48352Scael.Dv SIGKILL 51*48352Scaeland 52*48352Scael.Dv SIGSTOP 5320133Smckusicksignals, the 54*48352Scael.Fn signal 55*48352Scaelfunction allows for a signal to be caught, to be ignored, or to generate 56*48352Scaelan interupt. 57*48352ScaelThese signals are defined in the file 58*48352Scael.Aq Pa signal.h : 59*48352Scael.Bl -column SIGVTALARMXX "create core imagexxx" 60*48352Scael.It Sy " NAME " " Default Action " " Description" 61*48352Scael.It Dv SIGHUP No " terminate process" " terminal line hangup" 62*48352Scael.It Dv SIGINT No " terminate process" " interrupt program" 63*48352Scael.It Dv SIGQUIT No " create core image" " quit program" 64*48352Scael.It Dv SIGILL No " create core image" " illegal instruction" 65*48352Scael.It Dv SIGTRAP No " create core image" " trace trap" 66*48352Scael.It Dv SIGABRT No " create core image" Xr abort 2 67*48352Scaelcall (formerly 68*48352Scael.Dv SIGIOT ) 69*48352Scael.It Dv SIGEMT No " create core image" " emulate instruction executed" 70*48352Scael.It Dv SIGFPE No " create core image" " floating-point exception" 71*48352Scael.It Dv SIGKILL No " terminate process" " kill program" 72*48352Scael.It Dv SIGBUS No " create core image" " bus error" 73*48352Scael.It Dv SIGSEGV No " create core image" " segmentation violation" 74*48352Scael.It Dv SIGSYS No " create core image" " system call given invalid argument" 75*48352Scael.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 76*48352Scael.It Dv SIGALRM No " terminate process" " real-time timer expired" 77*48352Scael.It Dv SIGTERM No " terminate process" " software termination signal" 78*48352Scael.It Dv SIGURG No " discard signal" " urgent condition present on socket" 79*48352Scael.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 80*48352Scael.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 81*48352Scael.It Dv SIGCONT No " discard signal" " continue after stop" 82*48352Scael.It Dv SIGCHLD No " discard signal" " child status has changed" 83*48352Scael.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 84*48352Scael.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 85*48352Scael.It Dv SIGIO No " discard signal" Tn " I/O" 86*48352Scaelis possible on a descriptor (see 87*48352Scael.Xr fcntl 2 ) 88*48352Scael.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 89*48352Scael.Xr setrlimit 2 ) 90*48352Scael.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 91*48352Scael.Xr setrlimit 2 ) 92*48352Scael.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 93*48352Scael.Xr setitimer 2 ) 94*48352Scael.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 95*48352Scael.Xr setitimer 2 ) 96*48352Scael.It Dv SIGWINCH No " discard signal" " Window size change" 97*48352Scael.It Dv SIGINFO No " discard signal" " status request from keyboard" 98*48352Scael.It Dv SIGUSR1 No " terminate process" " User defined signal 1" 99*48352Scael.It Dv SIGUSR2 No " terminate process" " User defined signal 2" 100*48352Scael.El 101*48352Scael.Pp 102*48352ScaelThe 103*48352Scael.Fa func 104*48352Scaelprocedure allows a user to choose the action upon receipt of a signal. 105*48352ScaelTo set the default action of the signal to occur as listed above, 106*48352Scael.Fa func 107*48352Scaelshould be 108*48352Scael.Dv SIG_DFL . 109*48352ScaelA 110*48352Scael.Dv SIG_DFL 111*48352Scaelresets the default action. 112*48352ScaelTo ignore the signal 113*48352Scael.Fa func 114*48352Scaelshould be 115*48352Scael.Dv SIG_IGN . 116*48352ScaelThis will cause subsequent instances of the signal to be ignored 117*48352Scaeland pending instances to be discarded. If 118*48352Scael.Dv SIG_IGN 119*48352Scaelis not used, 12028312Sannefurther occurrences of the signal are 12120133Smckusickautomatically blocked and 122*48352Scael.Fa func 12320133Smckusickis called. 124*48352Scael.Pp 125*48352ScaelThe handled signal is unblocked with the 126*48352Scaelfunction returns and 127*48352Scaelthe process continues from where it left off when the signal occured. 128*48352Scael.Bf -symbolic 129*48352ScaelUnlike previous signal facilities, the handler 130*48352Scaelfunc() remains installed after a signal has been delivered. 131*48352Scael.Ef 132*48352Scael.Pp 133*48352ScaelFor some system calls, if a signal is caught while the call is 134*48352Scaelexecuting and the call is permaturely terminated, 135*48352Scaelthe call is automatically restarted. 136*48352Scael(The handler is installed using the 137*48352Scael.Dv SA_RESTART 138*48352Scaelflag with 139*48352Scael.Xr sigaction 2 . ) 14044871SkarelsThe affected system calls include 141*48352Scael.Xr read 2 , 142*48352Scael.Xr write 2 , 143*48352Scael.Xr sendto 2 , 144*48352Scael.Xr recvfrom 2 , 145*48352Scael.Xr sendmsg 2 14644871Skarelsand 147*48352Scael.Xr recvmsg 2 148*48352Scaelon a communications channel or a low speed device 14944871Skarelsand during a 150*48352Scael.Xr ioctl 2 15120132Smckusickor 152*48352Scael.Xr wait 2 . 15344871SkarelsHowever, calls that have already committed are not restarted, 15444871Skarelsbut instead return a partial success (for example, a short read count). 155*48352Scael.Pp 156*48352ScaelWhen a process which has installed signal handlers forks, 157*48352Scaelthe child process inherits the signals. 158*48352ScaelAll caught signals may be reset to their default action by a call 159*48352Scaelto the 160*48352Scael.Xr execve 2 161*48352Scaelfunction; 16220133Smckusickignored signals remain ignored. 163*48352Scael.Sh RETURN VALUES 16420133SmckusickThe previous action is returned on a successful call. 165*48352ScaelOtherwise, \-1 is returned and the global variable 166*48352Scael.Va errno 16720133Smckusickis set to indicate the error. 168*48352Scael.Sh ERRORS 169*48352Scael.Xr Signal 17020133Smckusickwill fail and no action will take place if one of the 17120133Smckusickfollowing occur: 172*48352Scael.Bl -tag -width [EINVAL] 173*48352Scael.It Bq Er EINVAL 174*48352Scael.Em Sig 17520133Smckusickis not a valid signal number. 176*48352Scael.It Bq Er EINVAL 177*48352ScaelAn attempt is made to ignore or supply a handler for 178*48352Scael.Dv SIGKILL 179*48352Scaelor 180*48352Scael.Ev SIGSTOP . 181*48352Scael.Sh SEE ALSO 182*48352Scael.Xr kill 1 , 183*48352Scael.Xr ptrace 2 , 184*48352Scael.Xr kill 2 , 185*48352Scael.Xr sigaction 2 , 186*48352Scael.Xr sigprocmask 2 , 187*48352Scael.Xr sigsuspend 2 , 188*48352Scael.Xr sigstack 2 , 189*48352Scael.Xr setjmp 3 , 190*48352Scael.Xr tty 4 191*48352Scael.Sh HISTORY 192*48352ScaelThis 193*48352Scael.Nm signal 194*48352Scaelfacility appeared in 195*48352Scael.Bx 4.0 . 196