move fakcu, perror, remove to stdio; fakcu goes away
[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.\"
bc9788fb 5.\" @(#)signal.3 6.5 (Berkeley) %G%
9d335a2c 6.\"
ec043d7a 7.TH SIGNAL 3C ""
9d335a2c 8.UC 4
3c31698f
KM
9.ie t .ds d \(dg
10.el .ds d \z'|+'
11.ie t .ds b \(bu
12.el .ds b @
9d335a2c 13.SH NAME
3c31698f 14signal \- simplified software signal facilities
9d335a2c
KM
15.SH SYNOPSIS
16.nf
17.B #include <signal.h>
18.PP
bc9788fb
MK
19.B void (*signal(sig, func))()
20.B void (*func)();
9d335a2c
KM
21.fi
22.SH DESCRIPTION
3c31698f
KM
23.I Signal
24is a simplified interface to the more general
bc9788fb 25.IR sigaction (2)
3c31698f 26facility.
9d335a2c
KM
27.PP
28A signal
29is generated by some abnormal event,
3c31698f 30initiated by a user at a terminal (quit, interrupt, stop),
9d335a2c 31by a program error (bus error, etc.),
3c31698f
KM
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
9d335a2c 46.I signal
3c31698f 47call allows signals either to be ignored
9d335a2c 48or to cause an interrupt to a specified location.
3c31698f
KM
49The following is a list of all signals with
50names as in the include file
51.RI < signal.h >:
9d335a2c
KM
52.LP
53.nf
3c31698f 54.ta \w'SIGVTALRM 'u +\w'15* 'u
9d335a2c
KM
55SIGHUP 1 hangup
56SIGINT 2 interrupt
57SIGQUIT 3* quit
3c31698f
KM
58SIGILL 4* illegal instruction
59SIGTRAP 5* trace trap
bc9788fb 60SIGABRT 6* \fIabort\fP() call (formerly SIGIOT)
9d335a2c
KM
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
3c31698f
KM
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))
c9d2bd73 82SIGWINCH 28\*b Window size change
bc9788fb 83SIGINFO 29\*b status request from keyboard
c44b06d2
KM
84SIGUSR1 30 User defined signal 1
85SIGUSR2 31 User defined signal 2
9d335a2c 86.fi
9d335a2c
KM
87.PP
88The starred signals in the list above cause a core image
89if not caught or ignored.
90.PP
91If
92.I func
93is SIG_DFL, the default action
94for signal
95.I sig
3c31698f
KM
96is reinstated; this default is termination
97(with a core image for starred signals)
98except for signals marked with \*b or \*d.
99Signals marked with \*b are discarded if the action
100is SIG_DFL; signals marked
101with \*d cause the process to stop.
9d335a2c
KM
102If
103.I func
3c31698f
KM
104is SIG_IGN the signal is subsequently ignored
105and pending instances of the signal are discarded.
106Otherwise, when the signal occurs
963ad392 107further occurrences of the signal are
3c31698f 108automatically blocked and
9d335a2c 109.I func
3c31698f 110is called.
9d335a2c 111.PP
3c31698f
KM
112A return from the function unblocks
113the handled signal and
114continues the process at the point it was interrupted.
115\fBUnlike previous signal facilities, the handler \fIfunc\fP
116remains installed after a signal has been delivered.\fP
9d335a2c 117.PP
3c31698f
KM
118If a caught signal occurs
119during certain system calls, causing
120the call to terminate prematurely, the call
bc9788fb
MK
121is automatically restarted
122(the handler is installed using the SA_RESTART flag with
123.IR sigaction (2)).
124The affected system calls include
125.IR read (2),
126.IR write (2),
127.IR sendto (2),
128.IR recvfrom (2),
129.IR sendmsg (2)
130and
131.IR recvmsg (2)
132on a communications channel or a slow device (such as a terminal,
133but not a regular file)
3c31698f 134and during a
bc9788fb
MK
135.IR wait (2)
136or
137.IR ioctl (2).
138However, calls that have already committed are not restarted,
139but instead return a partial success (for example, a short read count).
9d335a2c
KM
140.PP
141The value of
142.I signal
143is the previous (or initial)
144value of
145.I func
146for the particular signal.
147.PP
148After a
3c31698f
KM
149.IR fork (2)
150or
151.IR vfork (2)
9d335a2c
KM
152the child inherits
153all signals.
3c31698f
KM
154.IR Execve (2)
155resets all caught signals to the default action;
156ignored signals remain ignored.
157.SH "RETURN VALUE
158The previous action is returned on a successful call.
159Otherwise, \-1 is returned and
160.I errno
161is set to indicate the error.
162.SH ERRORS
163.I Signal
164will fail and no action will take place if one of the
165following occur:
166.TP 15
167[EINVAL]
168.I Sig
169is not a valid signal number.
170.TP 15
171[EINVAL]
172An attempt is made to ignore or supply a handler for SIGKILL
173or SIGSTOP.
9d335a2c 174.SH "SEE ALSO"
bc9788fb
MK
175kill(1), ptrace(2), kill(2),
176sigaction(2), sigprocmask(2), sigsuspend(2),
3c31698f
KM
177sigstack(2), setjmp(3), tty(4)
178.SH "NOTES (VAX-11)"
179The handler routine can be declared:
9d335a2c 180.PP
bc9788fb 181 void handler(sig, code, scp)
9d335a2c 182.PP
3c31698f
KM
183Here
184.I sig
185is the signal number, into which the hardware faults and traps are
186mapped as defined below. Code is a parameter which is either a constant
187as given below or, for compatibility mode faults, the code provided by
188the hardware.
189.I Scp
190is a pointer to the
191.I "struct sigcontext"
192used by the system to restore the process context from before
193the signal.
194Compatibility mode faults are distinguished from the
195other SIGILL traps by having PSL_CM set in the psl.
9d335a2c 196.PP
3c31698f
KM
197The following defines the mapping of hardware traps to signals
198and codes. All of these symbols are defined in
199.RI < signal.h >:
200.LP
201.ta \w' Floating/decimal divide by zero 'u +\w'15* 'u +8n
202.nf
203 Hardware condition Signal Code
204
205Arithmetic traps:
206 Integer overflow SIGFPE FPE_INTOVF_TRAP
207 Integer division by zero SIGFPE FPE_INTDIV_TRAP
208 Floating overflow trap SIGFPE FPE_FLTOVF_TRAP
209 Floating/decimal division by zero SIGFPE FPE_FLTDIV_TRAP
210 Floating underflow trap SIGFPE FPE_FLTUND_TRAP
211 Decimal overflow trap SIGFPE FPE_DECOVF_TRAP
212 Subscript-range SIGFPE FPE_SUBRNG_TRAP
213 Floating overflow fault SIGFPE FPE_FLTOVF_FAULT
214 Floating divide by zero fault SIGFPE FPE_FLTDIV_FAULT
215 Floating underflow fault SIGFPE FPE_FLTUND_FAULT
216Length access control SIGSEGV
217Protection violation SIGBUS
218Reserved instruction SIGILL ILL_RESAD_FAULT
219Customer-reserved instr. SIGEMT
220Reserved operand SIGILL ILL_PRIVIN_FAULT
221Reserved addressing SIGILL ILL_RESOP_FAULT
222Trace pending SIGTRAP
223Bpt instruction SIGTRAP
224Compatibility-mode SIGILL hardware supplied code
225Chme SIGSEGV
226Chms SIGSEGV
227Chmu SIGSEGV
228.fi