xref: /netbsd-src/lib/libc/gen/signal.3 (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1.\"	$NetBSD: signal.3,v 1.6 1996/03/26 02:05:55 jtc Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)signal.3	8.3 (Berkeley) 4/19/94
35.\"
36.Dd April 19, 1994
37.Dt SIGNAL 3
38.Os BSD 4
39.Sh NAME
40.Nm signal
41.Nd simplified software signal facilities
42.Sh SYNOPSIS
43.Fd #include <signal.h>
44.Ft void
45.\" can not do this with just .Fn yet
46.br
47.Po
48.Fn *signal "int sig" "void (*func)()"
49.Pc Ns \*(lp\*(rp
50.Sh DESCRIPTION
51This
52.Fn signal
53facility
54is a simplified interface to the more general
55.Xr sigaction 2
56facility.
57.Pp
58Signals allow the manipulation of a process from outside its
59domain as well as allowing the process to manipulate itself or
60copies of itself (children). There are two general types of signals:
61those that cause termination of a process and those that do not.
62Signals which cause termination of a program might result from
63an irrecoverable error or might be the result of a user at a terminal
64typing the `interrupt' character.
65Signals are used when a process is stopped because it wishes to access
66its control terminal while in the background (see
67.Xr tty 4 ) .
68Signals are optionally generated
69when a process resumes after being stopped,
70when the status of child processes changes,
71or when input is ready at the control terminal.
72Most signals result in the termination of the process receiving them
73if no action
74is taken; some signals instead cause the process receiving them
75to be stopped, or are simply discarded if the process has not
76requested otherwise.
77Except for the
78.Dv SIGKILL
79and
80.Dv SIGSTOP
81signals, the
82.Fn signal
83function allows for a signal to be caught, to be ignored, or to generate
84an interrupt.
85These signals are defined in the file
86.Aq Pa signal.h :
87.Bl -column SIGVTALARMXX "create core imagexxx"
88.It Sy "  Name  " "	  Default Action  " "	              Description"
89.It Dv SIGHUP No "	terminate process" "	terminal line hangup"
90.It Dv SIGINT No "	terminate process" "	interrupt program"
91.It Dv SIGQUIT No "	create core image" "	quit program"
92.It Dv SIGILL No "	create core image" "	illegal instruction"
93.It Dv SIGTRAP No "	create core image" "	trace trap"
94.It Dv SIGABRT No "	create core image" Xr 	abort 2
95call (formerly
96.Dv SIGIOT )
97.It Dv SIGEMT No "	create core image" "	emulate instruction executed"
98.It Dv SIGFPE No "	create core image" "	floating-point exception"
99.It Dv SIGKILL No "	terminate process" "	kill program"
100.It Dv SIGBUS No "	create core image" "	bus error"
101.It Dv SIGSEGV No "	create core image" "	segmentation violation"
102.It Dv SIGSYS No "	create core image" "	system call given invalid argument"
103.It Dv SIGPIPE No "	terminate process" "	write on a pipe with no reader"
104.It Dv SIGALRM No "	terminate process" "	real-time timer expired"
105.It Dv SIGTERM No "	terminate process" "	software termination signal"
106.It Dv SIGURG No "	discard signal" "	urgent condition present on socket"
107.It Dv SIGSTOP No "	stop process" "	stop (cannot be caught or ignored)"
108.It Dv SIGTSTP No "	stop process" "	stop signal generated from keyboard"
109.It Dv SIGCONT No "	discard signal" "	continue after stop"
110.It Dv SIGCHLD No "	discard signal" "	child status has changed"
111.It Dv SIGTTIN No "	stop process" "	background read attempted from control terminal"
112.It Dv SIGTTOU No "	stop process" "	background write attempted to control terminal"
113.It Dv SIGIO No "	discard signal" Tn "	I/O"
114is possible on a descriptor (see
115.Xr fcntl 2 )
116.It Dv SIGXCPU No "	terminate process" "	cpu time limit exceeded (see"
117.Xr setrlimit 2 )
118.It Dv SIGXFSZ No "	terminate process" "	file size limit exceeded (see"
119.Xr setrlimit 2 )
120.It Dv SIGVTALRM No "	terminate process" "	virtual time alarm (see"
121.Xr setitimer 2 )
122.It Dv SIGPROF No "	terminate process" "	profiling timer alarm (see"
123.Xr setitimer 2 )
124.It Dv SIGWINCH No "	discard signal" "	Window size change"
125.It Dv SIGINFO No "	discard signal" "	status request from keyboard"
126.It Dv SIGUSR1 No "	terminate process" "	User defined signal 1"
127.It Dv SIGUSR2 No "	terminate process" "	User defined signal 2"
128.El
129.Pp
130The
131.Fa func
132procedure allows a user to choose the action upon receipt of a signal.
133To set the default action of the signal to occur as listed above,
134.Fa func
135should be
136.Dv SIG_DFL .
137A
138.Dv SIG_DFL
139resets the default action.
140To ignore the signal
141.Fa func
142should be
143.Dv SIG_IGN .
144This will cause subsequent instances of the signal to be ignored
145and pending instances to be discarded. If
146.Dv SIG_IGN
147is not used,
148further occurrences of the signal are
149automatically blocked and
150.Fa func
151is called.
152.Pp
153The handled signal is unblocked with the
154function returns and
155the process continues from where it left off when the signal occurred.
156.Bf -symbolic
157Unlike previous signal facilities, the handler
158func() remains installed after a signal has been delivered.
159.Ef
160.Pp
161For some system calls, if a signal is caught while the call is
162executing and the call is prematurely terminated,
163the call is automatically restarted.
164(The handler is installed using the
165.Dv SA_RESTART
166flag with
167.Xr sigaction 2 . )
168The affected system calls include
169.Xr read 2 ,
170.Xr write 2 ,
171.Xr sendto 2 ,
172.Xr recvfrom 2 ,
173.Xr sendmsg 2
174and
175.Xr recvmsg 2
176on a communications channel or a low speed device
177and during a
178.Xr ioctl 2
179or
180.Xr wait 2 .
181However, calls that have already committed are not restarted,
182but instead return a partial success (for example, a short read count).
183.Pp
184When a process which has installed signal handlers forks,
185the child process inherits the signals.
186All caught signals may be reset to their default action by a call
187to the
188.Xr execve 2
189function;
190ignored signals remain ignored.
191.Sh RETURN VALUES
192The previous action is returned on a successful call.
193Otherwise, \-1 is returned and  the global variable
194.Va errno
195is set to indicate the error.
196.Sh ERRORS
197.Xr Signal
198will fail and no action will take place if one of the
199following occur:
200.Bl -tag -width Er
201.It Bq Er EINVAL
202.Em Sig
203is not a valid signal number.
204.It Bq Er EINVAL
205An attempt is made to ignore or supply a handler for
206.Dv SIGKILL
207or
208.Ev SIGSTOP .
209.Sh SEE ALSO
210.Xr kill 1 ,
211.Xr ptrace 2 ,
212.Xr kill 2 ,
213.Xr sigaction 2 ,
214.Xr sigaltstack 2 ,
215.Xr sigprocmask 2 ,
216.Xr sigsuspend 2 ,
217.Xr setjmp 3 ,
218.Xr tty 4
219.Sh HISTORY
220This
221.Nm signal
222facility appeared in
223.Bx 4.0 .
224