xref: /freebsd/lib/libc/gen/signal.3 (revision 0de89efe5c443f213c7ea28773ef2dc6cf3af2ed)
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.\"     @(#)signal.3	8.3 (Berkeley) 4/19/94
33.\"
34.Dd April 19, 1994
35.Dt SIGNAL 3
36.Os BSD 4
37.Sh NAME
38.Nm signal
39.Nd simplified software signal facilities
40.Sh SYNOPSIS
41.Fd #include <signal.h>
42.\" The following is Quite Ugly, but syntactically correct.  Don't try to
43.\" fix it.
44.Ft void \*(lp*
45.Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
46
47or in FreeBSD's equivalent but easier to read typedef'd version:
48.Ft typedef "void \*(lp*sig_t\*(rp \*(lpint\*(rp"
49.Ft sig_t
50.Fn signal "int sig" "sig_t func"
51.Sh DESCRIPTION
52This
53.Fn signal
54facility
55is a simplified interface to the more general
56.Xr sigaction 2
57facility.
58.Pp
59Signals allow the manipulation of a process from outside its
60domain as well as allowing the process to manipulate itself or
61copies of itself (children). There are two general types of signals:
62those that cause termination of a process and those that do not.
63Signals which cause termination of a program might result from
64an irrecoverable error or might be the result of a user at a terminal
65typing the `interrupt' character.
66Signals are used when a process is stopped because it wishes to access
67its control terminal while in the background (see
68.Xr tty 4 ) .
69Signals are optionally generated
70when a process resumes after being stopped,
71when the status of child processes changes,
72or when input is ready at the control terminal.
73Most signals result in the termination of the process receiving them
74if no action
75is taken; some signals instead cause the process receiving them
76to be stopped, or are simply discarded if the process has not
77requested otherwise.
78Except for the
79.Dv SIGKILL
80and
81.Dv SIGSTOP
82signals, the
83.Fn signal
84function allows for a signal to be caught, to be ignored, or to generate
85an interrupt.
86These signals are defined in the file
87.Aq Pa signal.h :
88.Bl -column SIGVTALARMXX "create core imagexxx"
89.It Sy "  Name  " "	  Default Action  " "	              Description"
90.It Dv SIGHUP No "	terminate process" "	terminal line hangup"
91.It Dv SIGINT No "	terminate process" "	interrupt program"
92.It Dv SIGQUIT No "	create core image" "	quit program"
93.It Dv SIGILL No "	create core image" "	illegal instruction"
94.It Dv SIGTRAP No "	create core image" "	trace trap"
95.It Dv SIGABRT No "	create core image" Xr 	abort 2
96call (formerly
97.Dv SIGIOT )
98.It Dv SIGEMT No "	create core image" "	emulate instruction executed"
99.It Dv SIGFPE No "	create core image" "	floating-point exception"
100.It Dv SIGKILL No "	terminate process" "	kill program"
101.It Dv SIGBUS No "	create core image" "	bus error"
102.It Dv SIGSEGV No "	create core image" "	segmentation violation"
103.It Dv SIGSYS No "	create core image" "	non-existent system call invoked"
104.It Dv SIGPIPE No "	terminate process" "	write on a pipe with no reader"
105.It Dv SIGALRM No "	terminate process" "	real-time timer expired"
106.It Dv SIGTERM No "	terminate process" "	software termination signal"
107.It Dv SIGURG No "	discard signal" "	urgent condition present on socket"
108.It Dv SIGSTOP No "	stop process" "	stop (cannot be caught or ignored)"
109.It Dv SIGTSTP No "	stop process" "	stop signal generated from keyboard"
110.It Dv SIGCONT No "	discard signal" "	continue after stop"
111.It Dv SIGCHLD No "	discard signal" "	child status has changed"
112.It Dv SIGTTIN No "	stop process" "	background read attempted from control terminal"
113.It Dv SIGTTOU No "	stop process" "	background write attempted to control terminal"
114.It Dv SIGIO No "	discard signal" Tn "	I/O"
115is possible on a descriptor (see
116.Xr fcntl 2 )
117.It Dv SIGXCPU No "	terminate process" "	cpu time limit exceeded (see"
118.Xr setrlimit 2 )
119.It Dv SIGXFSZ No "	terminate process" "	file size limit exceeded (see"
120.Xr setrlimit 2 )
121.It Dv SIGVTALRM No "	terminate process" "	virtual time alarm (see"
122.Xr setitimer 2 )
123.It Dv SIGPROF No "	terminate process" "	profiling timer alarm (see"
124.Xr setitimer 2 )
125.It Dv SIGWINCH No "	discard signal" "	Window size change"
126.It Dv SIGINFO No "	discard signal" "	status request from keyboard"
127.It Dv SIGUSR1 No "	terminate process" "	User defined signal 1"
128.It Dv SIGUSR2 No "	terminate process" "	User defined signal 2"
129.El
130.Pp
131The
132.Fa sig
133parameter specifies which signal was received.
134The
135.Fa func
136procedure allows a user to choose the action upon receipt of a signal.
137To set the default action of the signal to occur as listed above,
138.Fa func
139should be
140.Dv SIG_DFL .
141A
142.Dv SIG_DFL
143resets the default action.
144To ignore the signal
145.Fa func
146should be
147.Dv SIG_IGN .
148This will cause subsequent instances of the signal to be ignored
149and pending instances to be discarded. If
150.Dv SIG_IGN
151is not used,
152further occurrences of the signal are
153automatically blocked and
154.Fa func
155is called.
156.Pp
157The handled signal is unblocked when the
158function returns and
159the process continues from where it left off when the signal occurred.
160.Bf -symbolic
161Unlike previous signal facilities, the handler
162func() remains installed after a signal has been delivered.
163.Ef
164.Pp
165For some system calls, if a signal is caught while the call is
166executing and the call is prematurely terminated,
167the call is automatically restarted.
168(The handler is installed using the
169.Dv SA_RESTART
170flag with
171.Xr sigaction 2 . )
172The affected system calls include
173.Xr read 2 ,
174.Xr write 2 ,
175.Xr sendto 2 ,
176.Xr recvfrom 2 ,
177.Xr sendmsg 2
178and
179.Xr recvmsg 2
180on a communications channel or a low speed device
181and during a
182.Xr ioctl 2
183or
184.Xr wait 2 .
185However, calls that have already committed are not restarted,
186but instead return a partial success (for example, a short read count).
187.Pp
188When a process which has installed signal handlers forks,
189the child process inherits the signals.
190All caught signals may be reset to their default action by a call
191to the
192.Xr execve 2
193function;
194ignored signals remain ignored.
195.Sh RETURN VALUES
196The previous action is returned on a successful call.
197Otherwise, \-1 is returned and  the global variable
198.Va errno
199is set to indicate the error.
200.Sh ERRORS
201.Fn Signal
202will fail and no action will take place if one of the
203following occur:
204.Bl -tag -width [EINVAL]
205.It Bq Er EINVAL
206.Em Sig
207is not a valid signal number.
208.It Bq Er EINVAL
209An attempt is made to ignore or supply a handler for
210.Dv SIGKILL
211or
212.Ev SIGSTOP .
213.Sh SEE ALSO
214.Xr kill 1 ,
215.Xr kill 2 ,
216.Xr ptrace 2 ,
217.Xr sigaction 2 ,
218.Xr sigaltstack 2 ,
219.Xr sigprocmask 2 ,
220.Xr sigsuspend 2 ,
221.Xr setjmp 3 ,
222.Xr tty 4
223.Sh HISTORY
224This
225.Nm signal
226facility appeared in
227.Bx 4.0 .
228