xref: /minix3/lib/libc/gen/signal.3 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras.\"	$NetBSD: signal.3,v 1.24 2004/06/13 19:17:06 lha Exp $
2*2fe8fb19SBen Gras.\"
3*2fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993
4*2fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
5*2fe8fb19SBen Gras.\"
6*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
7*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
8*2fe8fb19SBen Gras.\" are met:
9*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
10*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
11*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
12*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
13*2fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
14*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
15*2fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
16*2fe8fb19SBen Gras.\"    without specific prior written permission.
17*2fe8fb19SBen Gras.\"
18*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*2fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*2fe8fb19SBen Gras.\" SUCH DAMAGE.
29*2fe8fb19SBen Gras.\"
30*2fe8fb19SBen Gras.\"     @(#)signal.3	8.3 (Berkeley) 4/19/94
31*2fe8fb19SBen Gras.\"
32*2fe8fb19SBen Gras.Dd June 11, 2004
33*2fe8fb19SBen Gras.Dt SIGNAL 3
34*2fe8fb19SBen Gras.Os
35*2fe8fb19SBen Gras.Sh NAME
36*2fe8fb19SBen Gras.Nm signal
37*2fe8fb19SBen Gras.Nd simplified software signal facilities
38*2fe8fb19SBen Gras.Sh LIBRARY
39*2fe8fb19SBen Gras.Lb libc
40*2fe8fb19SBen Gras.Sh SYNOPSIS
41*2fe8fb19SBen Gras.In signal.h
42*2fe8fb19SBen Gras.\" The following is Quite Ugly, but syntactically correct.  Don't try to
43*2fe8fb19SBen Gras.\" fix it.
44*2fe8fb19SBen Gras.Ft void \*(lp*
45*2fe8fb19SBen Gras.Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
46*2fe8fb19SBen Gras.Sh DESCRIPTION
47*2fe8fb19SBen GrasThis
48*2fe8fb19SBen Gras.Fn signal
49*2fe8fb19SBen Grasfacility
50*2fe8fb19SBen Grasis a simplified interface to the more general
51*2fe8fb19SBen Gras.Xr sigaction 2
52*2fe8fb19SBen Grasfacility.
53*2fe8fb19SBen Gras.Pp
54*2fe8fb19SBen GrasSignals allow the manipulation of a process from outside its
55*2fe8fb19SBen Grasdomain as well as allowing the process to manipulate itself or
56*2fe8fb19SBen Grascopies of itself (children).
57*2fe8fb19SBen GrasThere are two general types of signals:
58*2fe8fb19SBen Grasthose that cause termination of a process and those that do not.
59*2fe8fb19SBen GrasSignals which cause termination of a program might result from
60*2fe8fb19SBen Grasan irrecoverable error or might be the result of a user at a terminal
61*2fe8fb19SBen Grastyping the `interrupt' character.
62*2fe8fb19SBen GrasSignals are used when a process is stopped because it wishes to access
63*2fe8fb19SBen Grasits control terminal while in the background (see
64*2fe8fb19SBen Gras.Xr tty 4 ) .
65*2fe8fb19SBen GrasSignals are optionally generated
66*2fe8fb19SBen Graswhen a process resumes after being stopped,
67*2fe8fb19SBen Graswhen the status of child processes changes,
68*2fe8fb19SBen Grasor when input is ready at the control terminal.
69*2fe8fb19SBen GrasMost signals result in the termination of the process receiving them
70*2fe8fb19SBen Grasif no action
71*2fe8fb19SBen Grasis taken; some signals instead cause the process receiving them
72*2fe8fb19SBen Grasto be stopped, or are simply discarded if the process has not
73*2fe8fb19SBen Grasrequested otherwise.
74*2fe8fb19SBen GrasExcept for the
75*2fe8fb19SBen Gras.Dv SIGKILL
76*2fe8fb19SBen Grasand
77*2fe8fb19SBen Gras.Dv SIGSTOP
78*2fe8fb19SBen Grassignals, the
79*2fe8fb19SBen Gras.Fn signal
80*2fe8fb19SBen Grasfunction allows for a signal to be caught, to be ignored, or to generate
81*2fe8fb19SBen Grasan interrupt.
82*2fe8fb19SBen GrasSee
83*2fe8fb19SBen Gras.Xr signal 7
84*2fe8fb19SBen Grasfor comprehensive list of supported signals.
85*2fe8fb19SBen Gras.Pp
86*2fe8fb19SBen GrasThe
87*2fe8fb19SBen Gras.Fa func
88*2fe8fb19SBen Grasprocedure allows a user to choose the action upon receipt of a signal.
89*2fe8fb19SBen GrasTo set the default action of the signal to occur as listed above,
90*2fe8fb19SBen Gras.Fa func
91*2fe8fb19SBen Grasshould be
92*2fe8fb19SBen Gras.Dv SIG_DFL .
93*2fe8fb19SBen GrasA
94*2fe8fb19SBen Gras.Dv SIG_DFL
95*2fe8fb19SBen Grasresets the default action.
96*2fe8fb19SBen GrasTo ignore the signal
97*2fe8fb19SBen Gras.Fa func
98*2fe8fb19SBen Grasshould be
99*2fe8fb19SBen Gras.Dv SIG_IGN .
100*2fe8fb19SBen GrasThis will cause subsequent instances of the signal to be ignored
101*2fe8fb19SBen Grasand pending instances to be discarded.
102*2fe8fb19SBen GrasIf
103*2fe8fb19SBen Gras.Dv SIG_IGN
104*2fe8fb19SBen Grasis not used,
105*2fe8fb19SBen Grasfurther occurrences of the signal are
106*2fe8fb19SBen Grasautomatically blocked and
107*2fe8fb19SBen Gras.Fa func
108*2fe8fb19SBen Grasis called.
109*2fe8fb19SBen Gras.Pp
110*2fe8fb19SBen GrasThe handled signal is unblocked when the
111*2fe8fb19SBen Grasfunction returns and
112*2fe8fb19SBen Grasthe process continues from where it left off when the signal occurred.
113*2fe8fb19SBen Gras.Bf -symbolic
114*2fe8fb19SBen GrasUnlike previous signal facilities, the handler
115*2fe8fb19SBen Grasfunc() remains installed after a signal has been delivered.
116*2fe8fb19SBen Gras.Ef
117*2fe8fb19SBen Gras.Pp
118*2fe8fb19SBen GrasFor some system calls, if a signal is caught while the call is
119*2fe8fb19SBen Grasexecuting and the call is prematurely terminated,
120*2fe8fb19SBen Grasthe call is automatically restarted.
121*2fe8fb19SBen Gras(The handler is installed using the
122*2fe8fb19SBen Gras.Dv SA_RESTART
123*2fe8fb19SBen Grasflag with
124*2fe8fb19SBen Gras.Xr sigaction 2 ) .
125*2fe8fb19SBen GrasThe affected system calls include
126*2fe8fb19SBen Gras.Xr read 2 ,
127*2fe8fb19SBen Gras.Xr write 2 ,
128*2fe8fb19SBen Gras.Xr sendto 2 ,
129*2fe8fb19SBen Gras.Xr recvfrom 2 ,
130*2fe8fb19SBen Gras.Xr sendmsg 2
131*2fe8fb19SBen Grasand
132*2fe8fb19SBen Gras.Xr recvmsg 2
133*2fe8fb19SBen Grason a communications channel or a low speed device
134*2fe8fb19SBen Grasand during a
135*2fe8fb19SBen Gras.Xr ioctl 2
136*2fe8fb19SBen Grasor
137*2fe8fb19SBen Gras.Xr wait 2 .
138*2fe8fb19SBen GrasHowever, calls that have already committed are not restarted,
139*2fe8fb19SBen Grasbut instead return a partial success (for example, a short read count).
140*2fe8fb19SBen Gras.Pp
141*2fe8fb19SBen GrasWhen a process which has installed signal handlers forks,
142*2fe8fb19SBen Grasthe child process inherits the signals.
143*2fe8fb19SBen GrasAll caught signals may be reset to their default action by a call
144*2fe8fb19SBen Grasto the
145*2fe8fb19SBen Gras.Xr execve 2
146*2fe8fb19SBen Grasfunction;
147*2fe8fb19SBen Grasignored signals remain ignored.
148*2fe8fb19SBen Gras.Pp
149*2fe8fb19SBen GrasOnly functions that are async-signal-safe can safely be used in signal
150*2fe8fb19SBen Grashandlers, see
151*2fe8fb19SBen Gras.Xr signal 7
152*2fe8fb19SBen Grasfor a complete list.
153*2fe8fb19SBen Gras.Sh RETURN VALUES
154*2fe8fb19SBen GrasThe previous action is returned on a successful call.
155*2fe8fb19SBen GrasOtherwise,
156*2fe8fb19SBen Gras.Dv SIG_ERR
157*2fe8fb19SBen Grasis returned and the global variable
158*2fe8fb19SBen Gras.Va errno
159*2fe8fb19SBen Grasis set to indicate the error.
160*2fe8fb19SBen Gras.Sh ERRORS
161*2fe8fb19SBen Gras.Fn signal
162*2fe8fb19SBen Graswill fail and no action will take place if one of the following occur:
163*2fe8fb19SBen Gras.Bl -tag -width Er
164*2fe8fb19SBen Gras.It Bq Er EINVAL
165*2fe8fb19SBen GrasSpecified
166*2fe8fb19SBen Gras.Em sig
167*2fe8fb19SBen Grasis not a valid signal number.
168*2fe8fb19SBen Gras.It Bq Er EINVAL
169*2fe8fb19SBen GrasAn attempt is made to ignore or supply a handler for
170*2fe8fb19SBen Gras.Dv SIGKILL
171*2fe8fb19SBen Grasor
172*2fe8fb19SBen Gras.Dv SIGSTOP .
173*2fe8fb19SBen Gras.El
174*2fe8fb19SBen Gras.Sh SEE ALSO
175*2fe8fb19SBen Gras.Xr kill 1 ,
176*2fe8fb19SBen Gras.Xr kill 2 ,
177*2fe8fb19SBen Gras.Xr ptrace 2 ,
178*2fe8fb19SBen Gras.Xr sigaction 2 ,
179*2fe8fb19SBen Gras.Xr sigaltstack 2 ,
180*2fe8fb19SBen Gras.Xr sigprocmask 2 ,
181*2fe8fb19SBen Gras.Xr sigsuspend 2 ,
182*2fe8fb19SBen Gras.Xr psignal 3 ,
183*2fe8fb19SBen Gras.Xr setjmp 3 ,
184*2fe8fb19SBen Gras.Xr strsignal 3 ,
185*2fe8fb19SBen Gras.Xr tty 4 ,
186*2fe8fb19SBen Gras.Xr signal 7
187*2fe8fb19SBen Gras.Sh HISTORY
188*2fe8fb19SBen GrasThis
189*2fe8fb19SBen Gras.Fn signal
190*2fe8fb19SBen Grasfacility appeared in
191*2fe8fb19SBen Gras.Bx 4.0 .
192