BSD 3 development
[unix-history] / usr / man / man2 / signal.2
CommitLineData
e6817382
BJ
1.TH SIGNAL 2
2.SH NAME
3signal \- catch or ignore signals
4.SH SYNOPSIS
5.B #include <signal.h>
6.PP
7.B (*signal(sig, func))();
8.br
9.B (*func)();
10.SH DESCRIPTION
11A signal
12is generated by some abnormal event,
13initiated either by user at a terminal (quit, interrupt),
14by a program error (bus error, etc.),
15or by request of another program (kill).
16Normally all signals
17cause termination of the receiving process,
18but a
19.I signal
20call allows them either to be ignored
21or to cause an interrupt to a specified location.
22Here is the list of signals with names as in
23the include file.
24.LP
25.nf
26.ta \w'SIGMMMM 'u +\w'15* 'u
27SIGHUP 1 hangup
28SIGINT 2 interrupt
29SIGQUIT 3* quit
30SIGILL 4* illegal instruction (not reset when caught)
31SIGTRAP 5* trace trap (not reset when caught)
32SIGIOT 6* IOT instruction
33SIGEMT 7* EMT instruction
34SIGFPE 8* floating point exception
35SIGKILL 9 kill (cannot be caught or ignored)
36SIGBUS 10* bus error
37SIGSEGV 11* segmentation violation
38SIGSYS 12* bad argument to system call
39SIGPIPE 13 write on a pipe with no one to read it
40SIGALRM 14 alarm clock
41SIGTERM 15 software termination signal
42 16 unassigned
43.fi
44.PP
45The starred signals in the list above cause a core image
46if not caught or ignored.
47.PP
48If
49.I func
50is SIG_DFL, the default action
51for signal
52.I sig
53is reinstated; this default is termination,
54sometimes with a core image.
55If
56.I func
57is SIG_IGN the signal is ignored.
58Otherwise
59when the signal occurs
60.I func
61will be called with the
62signal number as argument.
63A return from the function will
64continue the process at the point it was interrupted.
65Except as indicated,
66a signal is reset to SIG_DFL after being caught.
67Thus if it is desired to
68catch every such signal,
69the catching routine must
70issue another
71.I signal
72call.
73.PP
74When a caught signal occurs
75during certain system calls, the call terminates prematurely.
76In particular this can occur
77during a
78.I read
79or
80.IR write (2)
81on a slow device (like a terminal; but not a file);
82and during
83.I pause
84or
85.IR wait (2).
86When such a signal occurs, the saved user status
87is arranged in such a way that when return from the
88signal-catching takes place, it will appear that the
89system call returned an error status.
90The user's program may then, if it wishes,
91re-execute the call.
92.PP
93The value of
94.I signal
95is the previous (or initial)
96value of
97.I func
98for the particular signal.
99.PP
100After a
101.IR fork (2)
102the child inherits
103all signals.
104.IR Exec (2)
105resets all
106caught signals to default action.
107.SH "SEE ALSO"
108kill(1), kill(2),
109ptrace(2),
110setjmp(3)
111.SH DIAGNOSTICS
112The value (int)\-1 is returned if the
113given signal is out of range.
114.SH BUGS
115If a repeated signal arrives before the last one can be
116reset, there is no chance to catch it.
117.PP
118The type specification of the routine and its
119.I func
120argument are problematical.
121.PP
122On the VAX-11, odd values for
123.I func
124are the same as SIG_IGN.
125.SH "ASSEMBLER (PDP-11)"
126(signal = 48.)
127.br
128.B sys signal; sig; label
129.br
130(old label in r0)
131.PP
132If
133.I label
134is 0,
135default action is reinstated.
136If
137.I label
138is odd, the signal is ignored.
139Any other even
140.I label
141specifies an address in the process
142where an interrupt is simulated.
143An RTI or RTT instruction will return from the
144interrupt.
145.SH "NOTES (VAX-11)"
146The following defines the mapping of hardware traps to signals:
147.PP
148.nf
149.ta \w' Floating divide by zero 'u +\w'15* 'u
150Arithemetic traps:
151.in +5
152Integer overflow SIGFPE
153Integer division by zero SIGFPE
154Floating overflow SIGFPE
155Floating underflow SIGFPE
156Floating division by zero SIGFPE
157Decimal division by zero SIGFPE
158Decimal overflow SIGFPE
159Subscript-range SIGFPE
160.in -5
161Access control (i.e. protection
162 violation)
163 except length violation SIGBUS
164Translation not valid, and
165 Length access control SIGSEGV
166Reserved instruction SIGILL
167Customer-reserved instr. SIGEMT
168Reserved operand SIGILL
169Reserved addressing SIGILL
170Trace pending SIGTRAP
171Bpt instruction SIGTRAP
172Compatibility-mode SIGEMT
173Chme SIGSEGV
174Chms SIGSEGV
175Chmu SIGBUS
176.fi