]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/signal.2
Automated addition of parentheses by add_parens_for_own_funcs.sh
[thirdparty/man-pages.git] / man2 / signal.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 2000 Andries Brouwer <aeb@cwi.nl>
2.\" based on work by Rik Faith <faith@cs.unc.edu>
3.\" and Mike Battersby <mike@starbug.apana.org.au>.
4.\"
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\"
197362df
MK
25.\" Modified 2004-11-19, mtk:
26.\" added pointer to sigaction.2 for details of ignoring SIGCHLD
27.\"
fea681da
MK
28.TH SIGNAL 2 2000-04-28 "Linux 2.2" "Linux Programmer's Manual"
29.SH NAME
30signal \- ANSI C signal handling
31.SH SYNOPSIS
32.B #include <signal.h>
33.sp
34.B typedef void (*sighandler_t)(int);
35.sp
36.BI "sighandler_t signal(int " signum ", sighandler_t " handler );
37.SH DESCRIPTION
38The
39.BR signal ()
40system call installs a new signal handler for the signal with number
41.IR signum .
42The signal handler is set to
43.I sighandler
44which may be a user specified function, or either
45.B SIG_IGN
46or
47.BR SIG_DFL .
48
49Upon arrival of a signal with number
50.I signum
51the following happens.
52If the corresponding handler is set to
53.BR SIG_IGN ,
54then the signal is ignored.
55If the handler is set to
56.BR SIG_DFL ,
99d2b7a2 57then the default action associated with the signal (see
fea681da
MK
58.BR signal (7))
59occurs.
60Finally, if the handler is set to a function
61.I sighandler
62then first either the handler is reset to SIG_DFL
63or an implementation-dependent blocking of the signal
64is performed and next
65.I sighandler
66is called with argument
67.IR signum .
68
69Using a signal handler function for a signal
70is called "catching the signal".
71The signals
72.B SIGKILL
73and
74.B SIGSTOP
75cannot be caught or ignored.
fea681da
MK
76.SH "RETURN VALUE"
77The
78.BR signal ()
79function returns the previous value of the signal handler, or
80.B SIG_ERR
81on error.
fea681da
MK
82.SH PORTABILITY
83The original Unix
84.BR signal ()
85would reset the handler to SIG_DFL, and System V
86(and the Linux kernel and libc4,5) does the same.
87On the other hand, BSD does not reset the handler, but blocks
88new instances of this signal from occurring during a call of the handler.
89The glibc2 library follows the BSD behaviour.
90
91If one on a libc5 system includes
92.B "<bsd/signal.h>"
93instead of
94.B "<signal.h>"
95then
e511ffb6 96.BR signal ()
fea681da
MK
97is redefined as
98.B __bsd_signal
99and signal has the BSD semantics. This is not recommended.
100
101If one on a glibc2 system defines a feature test
102macro such as
103.B _XOPEN_SOURCE
104or uses a separate
105.B sysv_signal
106function, one obtains classical behaviour. This is not recommended.
107
108Trying to change the semantics of this call using
109defines and includes is not a good idea. It is better to avoid
e511ffb6 110.BR signal ()
fea681da
MK
111altogether, and use
112.BR sigaction (2)
113instead.
fea681da
MK
114.SH NOTES
115The effects of this call in a multi-threaded process are unspecified.
116.PP
117The routine
118.I handler
119must be very careful, since processing elsewhere was interrupted
120at some arbitrary point. POSIX has the concept of "safe function".
121If a signal interrupts an unsafe function, and
122.I handler
123calls an unsafe function, then the behavior is undefined. Safe
124functions are listed explicitly in the various standards.
125The POSIX 1003.1-2003 list is
126
127_Exit()
128_exit()
129abort()
130accept()
131access()
132aio_error()
133aio_return()
134aio_suspend()
135alarm()
136bind()
137cfgetispeed()
138cfgetospeed()
139cfsetispeed()
140cfsetospeed()
141chdir()
142chmod()
143chown()
144clock_gettime()
145close()
146connect()
147creat()
148dup()
149dup2()
150execle()
151execve()
152fchmod()
153fchown()
154fcntl()
155fdatasync()
156fork()
157fpathconf()
158fstat()
159fsync()
160ftruncate()
161getegid()
162geteuid()
163getgid()
164getgroups()
165getpeername()
166getpgrp()
167getpid()
168getppid()
169getsockname()
170getsockopt()
171getuid()
172kill()
173link()
174listen()
175lseek()
176lstat()
177mkdir()
178mkfifo()
179open()
180pathconf()
181pause()
182pipe()
183poll()
184posix_trace_event()
185pselect()
186raise()
187read()
188readlink()
189recv()
190recvfrom()
191recvmsg()
192rename()
193rmdir()
194select()
195sem_post()
196send()
197sendmsg()
198sendto()
199setgid()
200setpgid()
201setsid()
202setsockopt()
203setuid()
204shutdown()
205sigaction()
206sigaddset()
207sigdelset()
208sigemptyset()
209sigfillset()
210sigismember()
211signal()
212sigpause()
213sigpending()
214sigprocmask()
215sigqueue()
216sigset()
217sigsuspend()
218sleep()
219socket()
220socketpair()
221stat()
222symlink()
223sysconf()
224tcdrain()
225tcflow()
226tcflush()
227tcgetattr()
228tcgetpgrp()
229tcsendbreak()
230tcsetattr()
231tcsetpgrp()
232time()
233timer_getoverrun()
234timer_gettime()
235timer_settime()
236times()
237umask()
238uname()
239unlink()
240utime()
241wait()
242waitpid()
243write().
244.PP
245According to POSIX, the behaviour of a process is undefined after it
246ignores a
247.BR SIGFPE ,
248.BR SIGILL ,
249or
250.B SIGSEGV
251signal that was not generated by the
252.BR kill (2)
253or the
254.BR raise (3)
255functions.
256Integer division by zero has undefined result.
257On some architectures it will generate a
258.B SIGFPE
259signal.
260(Also dividing the most negative integer by \-1 may generate
261.BR SIGFPE .)
262Ignoring this signal might lead to an endless loop.
263.PP
197362df
MK
264See
265.BR sigaction (2)
266for details on what happens when
fea681da
MK
267.B SIGCHLD
268is set to
269.BR SIG_IGN .
fea681da
MK
270.PP
271The use of
272.B sighandler_t
273is a GNU extension.
274Various versions of libc predefine this type; libc4 and libc5 define
275.IR SignalHandler ,
276glibc defines
277.I sig_t
278and, when
279.B _GNU_SOURCE
280is defined, also
281.IR sighandler_t .
282.SH "CONFORMING TO"
283ANSI C
fea681da
MK
284.SH "SEE ALSO"
285.BR kill (1),
286.BR alarm (2),
287.BR kill (2),
fea681da
MK
288.BR pause (2),
289.BR sigaction (2),
479377fb
MK
290.BR sigpending (2),
291.BR sigprocmask (2),
84b13f1e 292.BR sigqueue (2),
479377fb 293.BR sigsuspend (2),
fea681da 294.BR sigvec (2),
84b13f1e 295.BR killpg (3),
fea681da
MK
296.BR raise (3),
297.BR sigsetops (3),
298.BR signal (7)