xref: /minix/lib/libc/gen/signal.3 (revision 0a6a1f1d)
1.\"	$NetBSD: signal.3,v 1.24 2004/06/13 19:17:06 lha 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. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)signal.3	8.3 (Berkeley) 4/19/94
31.\"
32.Dd June 11, 2004
33.Dt SIGNAL 3
34.Os
35.Sh NAME
36.Nm signal
37.Nd simplified software signal facilities
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In 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.Sh DESCRIPTION
47This
48.Fn signal
49facility
50is a simplified interface to the more general
51.Xr sigaction 2
52facility.
53.Pp
54Signals allow the manipulation of a process from outside its
55domain as well as allowing the process to manipulate itself or
56copies of itself (children).
57There are two general types of signals:
58those that cause termination of a process and those that do not.
59Signals which cause termination of a program might result from
60an irrecoverable error or might be the result of a user at a terminal
61typing the `interrupt' character.
62Signals are used when a process is stopped because it wishes to access
63its control terminal while in the background (see
64.Xr tty 4 ) .
65Signals are optionally generated
66when a process resumes after being stopped,
67when the status of child processes changes,
68or when input is ready at the control terminal.
69Most signals result in the termination of the process receiving them
70if no action
71is taken; some signals instead cause the process receiving them
72to be stopped, or are simply discarded if the process has not
73requested otherwise.
74Except for the
75.Dv SIGKILL
76and
77.Dv SIGSTOP
78signals, the
79.Fn signal
80function allows for a signal to be caught, to be ignored, or to generate
81an interrupt.
82See
83.Xr signal 7
84for comprehensive list of supported signals.
85.Pp
86The
87.Fa func
88procedure allows a user to choose the action upon receipt of a signal.
89To set the default action of the signal to occur as listed above,
90.Fa func
91should be
92.Dv SIG_DFL .
93A
94.Dv SIG_DFL
95resets the default action.
96To ignore the signal
97.Fa func
98should be
99.Dv SIG_IGN .
100This will cause subsequent instances of the signal to be ignored
101and pending instances to be discarded.
102If
103.Dv SIG_IGN
104is not used,
105further occurrences of the signal are
106automatically blocked and
107.Fa func
108is called.
109.Pp
110The handled signal is unblocked when the
111function returns and
112the process continues from where it left off when the signal occurred.
113.Bf -symbolic
114Unlike previous signal facilities, the handler
115func() remains installed after a signal has been delivered.
116.Ef
117.Pp
118For some system calls, if a signal is caught while the call is
119executing and the call is prematurely terminated,
120the call is automatically restarted.
121(The handler is installed using the
122.Dv SA_RESTART
123flag with
124.Xr sigaction 2 ) .
125The affected system calls include
126.Xr read 2 ,
127.Xr write 2 ,
128.Xr sendto 2 ,
129.Xr recvfrom 2 ,
130.Xr sendmsg 2
131and
132.Xr recvmsg 2
133on a communications channel or a low speed device
134and during a
135.Xr ioctl 2
136or
137.Xr wait 2 .
138However, calls that have already committed are not restarted,
139but instead return a partial success (for example, a short read count).
140.Pp
141When a process which has installed signal handlers forks,
142the child process inherits the signals.
143All caught signals may be reset to their default action by a call
144to the
145.Xr execve 2
146function;
147ignored signals remain ignored.
148.Pp
149Only functions that are async-signal-safe can safely be used in signal
150handlers, see
151.Xr signal 7
152for a complete list.
153.Sh RETURN VALUES
154The previous action is returned on a successful call.
155Otherwise,
156.Dv SIG_ERR
157is returned and the global variable
158.Va errno
159is set to indicate the error.
160.Sh ERRORS
161.Fn signal
162will fail and no action will take place if one of the following occur:
163.Bl -tag -width Er
164.It Bq Er EINVAL
165Specified
166.Em sig
167is not a valid signal number.
168.It Bq Er EINVAL
169An attempt is made to ignore or supply a handler for
170.Dv SIGKILL
171or
172.Dv SIGSTOP .
173.El
174.Sh SEE ALSO
175.Xr kill 1 ,
176.Xr kill 2 ,
177.Xr ptrace 2 ,
178.Xr sigaction 2 ,
179.Xr sigaltstack 2 ,
180.Xr sigprocmask 2 ,
181.Xr sigsuspend 2 ,
182.Xr psignal 3 ,
183.Xr setjmp 3 ,
184.Xr strsignal 3 ,
185.Xr tty 4 ,
186.Xr signal 7
187.Sh HISTORY
188This
189.Fn signal
190facility appeared in
191.Bx 4.0 .
192