manual page distributed with 4.1BSD
[unix-history] / usr / src / lib / libc / gen / signal.3
CommitLineData
9d335a2c
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)signal.3 4.1 (Berkeley) %G%
6.\"
7.TH SIGNAL 2
8.UC 4
9.SH NAME
10signal \- catch or ignore signals
11.SH SYNOPSIS
12.nf
13.B #include <signal.h>
14.PP
15.B (*signal(sig, func))()
16.B void (*func)();
17.fi
18.SH DESCRIPTION
19.IR N.B. :
20The system currently supports two signal implementations.
21The one described here is standard in version 7 UNIX systems,
22and is retained for backward compatabililty.
23The one described in
24.IR sigsys (2)
25as supplemented by
26.IR sigset (3)
27provides for the needs of the job control mechanisms
28used by
29.IR csh (1),
30and corrects the bugs in this older implementation of signals,
31allowing programs
32which process interrupts
33to be written
34reliably.
35.PP
36A signal
37is generated by some abnormal event,
38initiated either by user at a terminal (quit, interrupt),
39by a program error (bus error, etc.),
40or by request of another program (kill).
41Normally all signals
42cause termination of the receiving process,
43but a
44.I signal
45call allows them either to be ignored
46or to cause an interrupt to a specified location.
47Here is the list of signals with names as in
48the include file.
49.LP
50.nf
51.ta \w'SIGMMMM 'u +\w'15* 'u
52SIGHUP 1 hangup
53SIGINT 2 interrupt
54SIGQUIT 3* quit
55SIGILL 4* illegal instruction (not reset when caught)
56SIGTRAP 5* trace trap (not reset when caught)
57SIGIOT 6* IOT instruction
58SIGEMT 7* EMT instruction
59SIGFPE 8* floating point exception
60SIGKILL 9 kill (cannot be caught or ignored)
61SIGBUS 10* bus error
62SIGSEGV 11* segmentation violation
63SIGSYS 12* bad argument to system call
64SIGPIPE 13 write on a pipe with no one to read it
65SIGALRM 14 alarm clock
66SIGTERM 15 software termination signal
67 16 unassigned
68.fi
69.IR N.B. :
70There are actually more signals; see
71.IR sigsys (2);
72the signals listed here are those of standard version 7.
73.PP
74The starred signals in the list above cause a core image
75if not caught or ignored.
76.PP
77If
78.I func
79is SIG_DFL, the default action
80for signal
81.I sig
82is reinstated; this default is termination,
83sometimes with a core image.
84If
85.I func
86is SIG_IGN the signal is ignored.
87Otherwise
88when the signal occurs
89.I func
90will be called with the
91signal number as argument.
92A return from the function will
93continue the process at the point it was interrupted.
94.PP
95Except as indicated,
96a signal is reset to SIG_DFL after being caught.
97Thus if it is desired to
98catch every such signal,
99the catching routine must
100issue another
101.I signal
102call.
103.PP
104If, when using this (older) signal interface,
105a caught signal occurs
106during certain system calls, the call terminates prematurely.
107In particular this can occur
108during an
109.IR ioctl ,
110.IR read ,
111or
112.IR write (2)
113on a slow device (like a terminal; but not a file);
114and during
115.I pause
116or
117.IR wait (2).
118When such a signal occurs, the saved user status
119is arranged in such a way that when return from the
120signal-catching takes place, it will appear that the
121system call returned an error status.
122The user's program may then, if it wishes,
123re-execute the call.
124.PP
125The value of
126.I signal
127is the previous (or initial)
128value of
129.I func
130for the particular signal.
131.PP
132After a
133.IR fork (2)
134the child inherits
135all signals.
136.IR Exec (2)
137resets all
138caught signals to default action.
139.PP
140If a process is using the mechanisms of
141.IR sigsys (2)
142and
143.IR sigset (3)
144then many of these calls are automatically restarted
145(See
146.IR sigsys (2)
147and
148.IR jobs (3)
149for details).
150.SH "SEE ALSO"
151sigsys(2),
152kill(1),
153kill(2),
154ptrace(2),
155setjmp(3),
156sigset(3)
157.SH DIAGNOSTICS
158The value (int)\-1 is returned if the
159given signal is out of range.
160.SH BUGS
161The traps should be distinguishable by extra arguments
162to the signal handler, and all hardware supplied parameters should
163be made available to the signal routine.
164.PP
165If a repeated signal arrives before the last one can be
166reset, there is no chance to catch it
167(however this is
168.B not
169true if you use
170.IR sigsys (2)
171and
172.IR sigset (3)).
173.PP
174The type specification of the routine and its
175.I func
176argument are problematical.
177.SH "ASSEMBLER (PDP-11)"
178(signal = 48.)
179.br
180.B sys signal; sig; label
181.br
182(old label in r0)
183.PP
184If
185.I label
186is 0,
187default action is reinstated.
188If
189.I label
190is 1, the signal is ignored.
191Any other even
192.I label
193specifies an address in the process
194where an interrupt is simulated.
195An RTI or RTT instruction will return from the
196interrupt.
197.SH "NOTES (VAX-11)"
198See
199.IR sigsys (2)
200for information on how hardware faults are mapped into signals.