148352Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 248352Scael.\" All rights reserved. 320132Smckusick.\" 448352Scael.\" %sccs.include.redist.man% 520132Smckusick.\" 6*51165Scael.\" @(#)signal.3 6.8 (Berkeley) 09/22/91 748352Scael.\" 848352Scael.Dd 948352Scael.Dt SIGNAL 3 1048352Scael.Os BSD 4 1148352Scael.Sh NAME 1248352Scael.Nm signal 1348352Scael.Nd simplified software signal facilities 1448352Scael.Sh SYNOPSIS 1548352Scael.Fd #include <signal.h> 1648352Scael.Ft void 17*51165Scael.Fn *signal sig func\*(lp\*(rp 1850725Scael.Ft void 1948352Scael.\" can not do this with .Fn yet 2048352Scael.br 2150725Scael\*(lp\|\*(fN*func\*(rp\*(lp\|\*(rp\fR 2248352Scael.Sh DESCRIPTION 2348352ScaelThis 2448352Scael.Fn signal 2548352Scaelfacility 2620133Smckusickis a simplified interface to the more general 2748352Scael.Xr sigaction 2 2820133Smckusickfacility. 2948352Scael.Pp 3048352ScaelSignals allow the manipulation of a process from outside its 3148352Scaeldomain as well as allowing the process to manipulate itself or 3248352Scaelcopies of itself (children). There are two general types of signals: 3348352Scaelthose that cause termination of a process and those that do not. 3448352ScaelSignals which cause termination of a program might result from 3548352Scaelan irrecoverable error or might be the result of a user at a terminal 3648352Scaeltyping the `interrupt' character. 3748352ScaelSignals are used when a process is stopped because it wishes to access 3820133Smckusickits control terminal while in the background (see 3948352Scael.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. 4448352ScaelMost signals result in the termination of the process receiving them 4548352Scaelif 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. 4948352ScaelExcept for the 5048352Scael.Dv SIGKILL 5148352Scaeland 5248352Scael.Dv SIGSTOP 5320133Smckusicksignals, the 5448352Scael.Fn signal 5548352Scaelfunction allows for a signal to be caught, to be ignored, or to generate 5648352Scaelan interupt. 5748352ScaelThese signals are defined in the file 5848352Scael.Aq Pa signal.h : 5948352Scael.Bl -column SIGVTALARMXX "create core imagexxx" 6050725Scael.It Sy " Name " " Default Action " " Description" 6148352Scael.It Dv SIGHUP No " terminate process" " terminal line hangup" 6248352Scael.It Dv SIGINT No " terminate process" " interrupt program" 6348352Scael.It Dv SIGQUIT No " create core image" " quit program" 6448352Scael.It Dv SIGILL No " create core image" " illegal instruction" 6548352Scael.It Dv SIGTRAP No " create core image" " trace trap" 6648352Scael.It Dv SIGABRT No " create core image" Xr abort 2 6748352Scaelcall (formerly 6848352Scael.Dv SIGIOT ) 6948352Scael.It Dv SIGEMT No " create core image" " emulate instruction executed" 7048352Scael.It Dv SIGFPE No " create core image" " floating-point exception" 7148352Scael.It Dv SIGKILL No " terminate process" " kill program" 7248352Scael.It Dv SIGBUS No " create core image" " bus error" 7348352Scael.It Dv SIGSEGV No " create core image" " segmentation violation" 7448352Scael.It Dv SIGSYS No " create core image" " system call given invalid argument" 7548352Scael.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" 7648352Scael.It Dv SIGALRM No " terminate process" " real-time timer expired" 7748352Scael.It Dv SIGTERM No " terminate process" " software termination signal" 7848352Scael.It Dv SIGURG No " discard signal" " urgent condition present on socket" 7948352Scael.It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)" 8048352Scael.It Dv SIGTSTP No " stop process" " stop signal generated from keyboard" 8148352Scael.It Dv SIGCONT No " discard signal" " continue after stop" 8248352Scael.It Dv SIGCHLD No " discard signal" " child status has changed" 8348352Scael.It Dv SIGTTIN No " stop process" " background read attempted from control terminal" 8448352Scael.It Dv SIGTTOU No " stop process" " background write attempted to control terminal" 8548352Scael.It Dv SIGIO No " discard signal" Tn " I/O" 8648352Scaelis possible on a descriptor (see 8748352Scael.Xr fcntl 2 ) 8848352Scael.It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see" 8948352Scael.Xr setrlimit 2 ) 9048352Scael.It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see" 9148352Scael.Xr setrlimit 2 ) 9248352Scael.It Dv SIGVTALRM No " terminate process" " virtual time alarm (see" 9348352Scael.Xr setitimer 2 ) 9448352Scael.It Dv SIGPROF No " terminate process" " profiling timer alarm (see" 9548352Scael.Xr setitimer 2 ) 9648352Scael.It Dv SIGWINCH No " discard signal" " Window size change" 9748352Scael.It Dv SIGINFO No " discard signal" " status request from keyboard" 9848352Scael.It Dv SIGUSR1 No " terminate process" " User defined signal 1" 9948352Scael.It Dv SIGUSR2 No " terminate process" " User defined signal 2" 10048352Scael.El 10148352Scael.Pp 10248352ScaelThe 10348352Scael.Fa func 10448352Scaelprocedure allows a user to choose the action upon receipt of a signal. 10548352ScaelTo set the default action of the signal to occur as listed above, 10648352Scael.Fa func 10748352Scaelshould be 10848352Scael.Dv SIG_DFL . 10948352ScaelA 11048352Scael.Dv SIG_DFL 11148352Scaelresets the default action. 11248352ScaelTo ignore the signal 11348352Scael.Fa func 11448352Scaelshould be 11548352Scael.Dv SIG_IGN . 11648352ScaelThis will cause subsequent instances of the signal to be ignored 11748352Scaeland pending instances to be discarded. If 11848352Scael.Dv SIG_IGN 11948352Scaelis not used, 12028312Sannefurther occurrences of the signal are 12120133Smckusickautomatically blocked and 12248352Scael.Fa func 12320133Smckusickis called. 12448352Scael.Pp 12548352ScaelThe handled signal is unblocked with the 12648352Scaelfunction returns and 12748352Scaelthe process continues from where it left off when the signal occured. 12848352Scael.Bf -symbolic 12948352ScaelUnlike previous signal facilities, the handler 13048352Scaelfunc() remains installed after a signal has been delivered. 13148352Scael.Ef 13248352Scael.Pp 13348352ScaelFor some system calls, if a signal is caught while the call is 13448352Scaelexecuting and the call is permaturely terminated, 13548352Scaelthe call is automatically restarted. 13648352Scael(The handler is installed using the 13748352Scael.Dv SA_RESTART 13848352Scaelflag with 13948352Scael.Xr sigaction 2 . ) 14044871SkarelsThe affected system calls include 14148352Scael.Xr read 2 , 14248352Scael.Xr write 2 , 14348352Scael.Xr sendto 2 , 14448352Scael.Xr recvfrom 2 , 14548352Scael.Xr sendmsg 2 14644871Skarelsand 14748352Scael.Xr recvmsg 2 14848352Scaelon a communications channel or a low speed device 14944871Skarelsand during a 15048352Scael.Xr ioctl 2 15120132Smckusickor 15248352Scael.Xr wait 2 . 15344871SkarelsHowever, calls that have already committed are not restarted, 15444871Skarelsbut instead return a partial success (for example, a short read count). 15548352Scael.Pp 15648352ScaelWhen a process which has installed signal handlers forks, 15748352Scaelthe child process inherits the signals. 15848352ScaelAll caught signals may be reset to their default action by a call 15948352Scaelto the 16048352Scael.Xr execve 2 16148352Scaelfunction; 16220133Smckusickignored signals remain ignored. 16348352Scael.Sh RETURN VALUES 16420133SmckusickThe previous action is returned on a successful call. 16548352ScaelOtherwise, \-1 is returned and the global variable 16648352Scael.Va errno 16720133Smckusickis set to indicate the error. 16848352Scael.Sh ERRORS 16948352Scael.Xr Signal 17020133Smckusickwill fail and no action will take place if one of the 17120133Smckusickfollowing occur: 17248352Scael.Bl -tag -width [EINVAL] 17348352Scael.It Bq Er EINVAL 17448352Scael.Em Sig 17520133Smckusickis not a valid signal number. 17648352Scael.It Bq Er EINVAL 17748352ScaelAn attempt is made to ignore or supply a handler for 17848352Scael.Dv SIGKILL 17948352Scaelor 18048352Scael.Ev SIGSTOP . 18148352Scael.Sh SEE ALSO 18248352Scael.Xr kill 1 , 18348352Scael.Xr ptrace 2 , 18448352Scael.Xr kill 2 , 18548352Scael.Xr sigaction 2 , 18648352Scael.Xr sigprocmask 2 , 18748352Scael.Xr sigsuspend 2 , 18848352Scael.Xr sigstack 2 , 18948352Scael.Xr setjmp 3 , 19048352Scael.Xr tty 4 19148352Scael.Sh HISTORY 19248352ScaelThis 19348352Scael.Nm signal 19448352Scaelfacility appeared in 19548352Scael.Bx 4.0 . 196