spelling correction
[unix-history] / usr / src / lib / libc / gen / signal.3
... / ...
CommitLineData
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 6.4 (Berkeley) %G%
6.\"
7.TH SIGNAL 3C ""
8.UC 4
9.ie t .ds d \(dg
10.el .ds d \z'|+'
11.ie t .ds b \(bu
12.el .ds b @
13.SH NAME
14signal \- simplified software signal facilities
15.SH SYNOPSIS
16.nf
17.B #include <signal.h>
18.PP
19.B (*signal(sig, func))()
20.B int (*func)();
21.fi
22.SH DESCRIPTION
23.I Signal
24is a simplified interface to the more general
25.IR sigvec (2)
26facility.
27.PP
28A signal
29is generated by some abnormal event,
30initiated by a user at a terminal (quit, interrupt, stop),
31by a program error (bus error, etc.),
32by request of another program (kill),
33or when a process is stopped because it wishes to access
34its control terminal while in the background (see
35.IR tty (4)).
36Signals are optionally generated
37when a process resumes after being stopped,
38when the status of child processes changes,
39or when input is ready at the control terminal.
40Most signals cause termination of the receiving process if no action
41is taken; some signals instead cause the process receiving them
42to be stopped, or are simply discarded if the process has not
43requested otherwise.
44Except for the SIGKILL and SIGSTOP
45signals, the
46.I signal
47call allows signals either to be ignored
48or to cause an interrupt to a specified location.
49The following is a list of all signals with
50names as in the include file
51.RI < signal.h >:
52.LP
53.nf
54.ta \w'SIGVTALRM 'u +\w'15* 'u
55SIGHUP 1 hangup
56SIGINT 2 interrupt
57SIGQUIT 3* quit
58SIGILL 4* illegal instruction
59SIGTRAP 5* trace trap
60SIGIOT 6* IOT instruction
61SIGEMT 7* EMT instruction
62SIGFPE 8* floating point exception
63SIGKILL 9 kill (cannot be caught or ignored)
64SIGBUS 10* bus error
65SIGSEGV 11* segmentation violation
66SIGSYS 12* bad argument to system call
67SIGPIPE 13 write on a pipe with no one to read it
68SIGALRM 14 alarm clock
69SIGTERM 15 software termination signal
70SIGURG 16\*b urgent condition present on socket
71SIGSTOP 17\*d stop (cannot be caught or ignored)
72SIGTSTP 18\*d stop signal generated from keyboard
73SIGCONT 19\*b continue after stop
74SIGCHLD 20\*b child status has changed
75SIGTTIN 21\*d background read attempted from control terminal
76SIGTTOU 22\*d background write attempted to control terminal
77SIGIO 23\*b i/o is possible on a descriptor (see \fIfcntl\fP(2))
78SIGXCPU 24 cpu time limit exceeded (see \fIsetrlimit\fP(2))
79SIGXFSZ 25 file size limit exceeded (see \fIsetrlimit\fP(2))
80SIGVTALRM 26 virtual time alarm (see \fIsetitimer\fP(2))
81SIGPROF 27 profiling timer alarm (see \fIsetitimer\fP(2))
82SIGWINCH 28\*b Window size change
83SIGUSR1 30 User defined signal 1
84SIGUSR2 31 User defined signal 2
85.fi
86.PP
87The starred signals in the list above cause a core image
88if not caught or ignored.
89.PP
90If
91.I func
92is SIG_DFL, the default action
93for signal
94.I sig
95is reinstated; this default is termination
96(with a core image for starred signals)
97except for signals marked with \*b or \*d.
98Signals marked with \*b are discarded if the action
99is SIG_DFL; signals marked
100with \*d cause the process to stop.
101If
102.I func
103is SIG_IGN the signal is subsequently ignored
104and pending instances of the signal are discarded.
105Otherwise, when the signal occurs
106further occurrences of the signal are
107automatically blocked and
108.I func
109is called.
110.PP
111A return from the function unblocks
112the handled signal and
113continues the process at the point it was interrupted.
114\fBUnlike previous signal facilities, the handler \fIfunc\fP
115remains installed after a signal has been delivered.\fP
116.PP
117If a caught signal occurs
118during certain system calls, causing
119the call to terminate prematurely, the call
120is automatically restarted.
121In particular this can occur
122during a
123.I read
124or
125.IR write (2)
126on a slow device (such as a terminal; but not a file)
127and during a
128.IR wait (2).
129.PP
130The value of
131.I signal
132is the previous (or initial)
133value of
134.I func
135for the particular signal.
136.PP
137After a
138.IR fork (2)
139or
140.IR vfork (2)
141the child inherits
142all signals.
143.IR Execve (2)
144resets all caught signals to the default action;
145ignored signals remain ignored.
146.SH "RETURN VALUE
147The previous action is returned on a successful call.
148Otherwise, \-1 is returned and
149.I errno
150is set to indicate the error.
151.SH ERRORS
152.I Signal
153will fail and no action will take place if one of the
154following occur:
155.TP 15
156[EINVAL]
157.I Sig
158is not a valid signal number.
159.TP 15
160[EINVAL]
161An attempt is made to ignore or supply a handler for SIGKILL
162or SIGSTOP.
163.TP 15
164[EINVAL]
165An attempt is made to ignore SIGCONT (by default SIGCONT
166is ignored).
167.SH "SEE ALSO"
168kill(1),
169ptrace(2), kill(2),
170sigvec(2), sigblock(2), sigsetmask(2), sigpause(2),
171sigstack(2), setjmp(3), tty(4)
172.SH "NOTES (VAX-11)"
173The handler routine can be declared:
174.PP
175 handler(sig, code, scp)
176.PP
177Here
178.I sig
179is the signal number, into which the hardware faults and traps are
180mapped as defined below. Code is a parameter which is either a constant
181as given below or, for compatibility mode faults, the code provided by
182the hardware.
183.I Scp
184is a pointer to the
185.I "struct sigcontext"
186used by the system to restore the process context from before
187the signal.
188Compatibility mode faults are distinguished from the
189other SIGILL traps by having PSL_CM set in the psl.
190.PP
191The following defines the mapping of hardware traps to signals
192and codes. All of these symbols are defined in
193.RI < signal.h >:
194.LP
195.ta \w' Floating/decimal divide by zero 'u +\w'15* 'u +8n
196.nf
197 Hardware condition Signal Code
198
199Arithmetic traps:
200 Integer overflow SIGFPE FPE_INTOVF_TRAP
201 Integer division by zero SIGFPE FPE_INTDIV_TRAP
202 Floating overflow trap SIGFPE FPE_FLTOVF_TRAP
203 Floating/decimal division by zero SIGFPE FPE_FLTDIV_TRAP
204 Floating underflow trap SIGFPE FPE_FLTUND_TRAP
205 Decimal overflow trap SIGFPE FPE_DECOVF_TRAP
206 Subscript-range SIGFPE FPE_SUBRNG_TRAP
207 Floating overflow fault SIGFPE FPE_FLTOVF_FAULT
208 Floating divide by zero fault SIGFPE FPE_FLTDIV_FAULT
209 Floating underflow fault SIGFPE FPE_FLTUND_FAULT
210Length access control SIGSEGV
211Protection violation SIGBUS
212Reserved instruction SIGILL ILL_RESAD_FAULT
213Customer-reserved instr. SIGEMT
214Reserved operand SIGILL ILL_PRIVIN_FAULT
215Reserved addressing SIGILL ILL_RESOP_FAULT
216Trace pending SIGTRAP
217Bpt instruction SIGTRAP
218Compatibility-mode SIGILL hardware supplied code
219Chme SIGSEGV
220Chms SIGSEGV
221Chmu SIGSEGV
222.fi