1<signal.h>(0P) POSIX Programmer's Manual <signal.h>(0P)
2
3
4
6 signal.h - signals
7
9 #include <signal.h>
10
12 Some of the functionality described on this reference page extends the
13 ISO C standard. Applications shall define the appropriate feature test
14 macro (see the System Interfaces volume of IEEE Std 1003.1-2001, Sec‐
15 tion 2.2, The Compilation Environment) to enable the visibility of
16 these symbols in this header.
17
18 The <signal.h> header shall define the following symbolic constants,
19 each of which expands to a distinct constant expression of the type:
20
21
22 void (*)(int)
23
24 whose value matches no declarable function.
25
26 SIG_DFL
27 Request for default signal handling.
28
29 SIG_ERR
30 Return value from signal() in case of error.
31
32 SIG_HOLD
33 Request that signal be held.
34
35 SIG_IGN
36 Request that signal be ignored.
37
38
39 The following data types shall be defined through typedef:
40
41 sig_atomic_t
42 Possibly volatile-qualified integer type of an object that can
43 be accessed as an atomic entity, even in the presence of asyn‐
44 chronous interrupts.
45
46 sigset_t
47 Integer or structure type of an object used to represent sets of
48 signals.
49
50 pid_t As described in <sys/types.h> .
51
52
53 The <signal.h> header shall define the sigevent structure, which has at
54 least the following members:
55
56
57 int sigev_notify Notification type.
58 int sigev_signo Signal number.
59 union sigval sigev_value Signal value.
60 void(*)(union sigval) sigev_notify_function Notification function.
61 (pthread_attr_t *) sigev_notify_attributes Notification attributes.
62
63 The following values of sigev_notify shall be defined:
64
65 SIGEV_NONE
66 No asynchronous notification is delivered when the event of
67 interest occurs.
68
69 SIGEV_SIGNAL
70 A queued signal, with an application-defined value, is generated
71 when the event of interest occurs.
72
73 SIGEV_THREAD
74 A notification function is called to perform notification.
75
76
77 The sigval union shall be defined as:
78
79
80 int sival_int Integer signal value.
81 void *sival_ptr Pointer signal value.
82
83 This header shall also declare the macros SIGRTMIN and SIGRTMAX, which
84 evaluate to integer expressions, and specify a range of signal numbers
85 that are reserved for application use and for which the realtime signal
86 behavior specified in this volume of IEEE Std 1003.1-2001 is supported.
87 The signal numbers in this range do not overlap any of the signals
88 specified in the following table.
89
90 The range SIGRTMIN through SIGRTMAX inclusive shall include at least
91 {RTSIG_MAX} signal numbers.
92
93 It is implementation-defined whether realtime signal behavior is sup‐
94 ported for other signals.
95
96 This header also declares the constants that are used to refer to the
97 signals that occur in the system. Signals defined here begin with the
98 letters SIG. Each of the signals have distinct positive integer values.
99 The value 0 is reserved for use as the null signal (see kill()). Addi‐
100 tional implementation-defined signals may occur in the system.
101
102 The ISO C standard only requires the signal names SIGABRT, SIGFPE, SIG‐
103 ILL, SIGINT, SIGSEGV, and SIGTERM to be defined.
104
105 The following signals shall be supported on all implementations
106 (default actions are explained below the table):
107
108 Signal Default Action Description
109 SIGABRT A Process abort signal.
110 SIGALRM T Alarm clock.
111 SIGBUS A Access to an undefined portion of a mem‐
112 ory object.
113 SIGCHLD I Child process terminated, stopped,
114 or continued.
115 SIGCONT C Continue executing, if stopped.
116 SIGFPE A Erroneous arithmetic operation.
117 SIGHUP T Hangup.
118 SIGILL A Illegal instruction.
119 SIGINT T Terminal interrupt signal.
120 SIGKILL T Kill (cannot be caught or ignored).
121 SIGPIPE T Write on a pipe with no one to read it.
122 SIGQUIT A Terminal quit signal.
123 SIGSEGV A Invalid memory reference.
124 SIGSTOP S Stop executing (cannot be caught or
125 ignored).
126 SIGTERM T Termination signal.
127 SIGTSTP S Terminal stop signal.
128 SIGTTIN S Background process attempting read.
129 SIGTTOU S Background process attempting write.
130 SIGUSR1 T User-defined signal 1.
131 SIGUSR2 T User-defined signal 2.
132 SIGPOLL T Pollable event.
133 SIGPROF T Profiling timer expired.
134
135 SIGSYS A Bad system call.
136 SIGTRAP A Trace/breakpoint trap.
137 SIGURG I High bandwidth data is available at a
138 socket.
139 SIGVTALRM T Virtual timer expired.
140 SIGXCPU A CPU time limit exceeded.
141 SIGXFSZ A File size limit exceeded.
142
143 The default actions are as follows:
144
145 T Abnormal termination of the process. The process is terminated
146 with all the consequences of _exit() except that the status made
147 available to wait() and waitpid() indicates abnormal termination
148 by the specified signal.
149
150 A Abnormal termination of the process.
151 Additionally, implementation-defined abnormal termination
152 actions, such as creation of a core file, may occur.
153
154 I Ignore the signal.
155
156 S Stop the process.
157
158 C Continue the process, if it is stopped; otherwise, ignore the
159 signal.
160
161
162
163 The header shall provide a declaration of struct sigaction, including
164 at least the following members:
165
166
167 void (*sa_handler)(int) Pointer to a signal-catching function or one of the macros
168 SIG_IGN or SIG_DFL.
169 sigset_t sa_mask Set of signals to be blocked during execution of the signal
170 handling function.
171 int sa_flags Special flags.
172 void (*sa_sigaction)(int, siginfo_t *, void *)
173 Pointer to a signal-catching function.
174
175 The storage occupied by sa_handler and sa_sigaction may overlap, and a
176 conforming application shall not use both simultaneously.
177
178 The following shall be declared as constants:
179
180 SA_NOCLDSTOP
181 Do not generate SIGCHLD when children stop
182 or stopped children continue.
183
184 SIG_BLOCK
185 The resulting set is the union of the current set and the signal
186 set pointed to by the argument set.
187
188 SIG_UNBLOCK
189 The resulting set is the intersection of the current set and the
190 complement of the signal set pointed to by the argument set.
191
192 SIG_SETMASK
193 The resulting set is the signal set pointed to by the argument
194 set.
195
196 SA_ONSTACK
197 Causes signal delivery to occur on an alternate stack.
198
199 SA_RESETHAND
200 Causes signal dispositions to be set to SIG_DFL on entry to sig‐
201 nal handlers.
202
203 SA_RESTART
204 Causes certain functions to become restartable.
205
206 SA_SIGINFO
207 Causes extra information to be passed to signal handlers at the
208 time of receipt of a signal.
209
210 SA_NOCLDWAIT
211 Causes implementations not to create zombie processes on child
212 death.
213
214 SA_NODEFER
215 Causes signal not to be automatically blocked on entry to signal
216 handler.
217
218 SS_ONSTACK
219 Process is executing on an alternate signal stack.
220
221 SS_DISABLE
222 Alternate signal stack is disabled.
223
224 MINSIGSTKSZ
225 Minimum stack size for a signal handler.
226
227 SIGSTKSZ
228 Default size in bytes for the alternate signal stack.
229
230
231 The ucontext_t structure shall be defined through typedef as described
232 in <ucontext.h>.
233
234 The mcontext_t type shall be defined through typedef as described in
235 <ucontext.h>.
236
237 The <signal.h> header shall define the stack_t type as a structure that
238 includes at least the following members:
239
240
241 void *ss_sp Stack base or pointer.
242 size_t ss_size Stack size.
243 int ss_flags Flags.
244
245 The <signal.h> header shall define the sigstack structure that includes
246 at least the following members:
247
248
249 int ss_onstack Non-zero when signal stack is in use.
250 void *ss_sp Signal stack pointer.
251
252 The <signal.h> header shall define the siginfo_t type as a structure
253 that includes at least the following members:
254
255
256 int si_signo Signal number.
257
258
259 int si_errno If non-zero, an errno value associated with
260 this signal, as defined in <errno.h>.
261
262
263 int si_code Signal code.
264
265
266 pid_t si_pid Sending process ID.
267 uid_t si_uid Real user ID of sending process.
268 void *si_addr Address of faulting instruction.
269 int si_status Exit value or signal.
270 long si_band Band event for SIGPOLL.
271
272
273 union sigval si_value Signal value.
274
275
276 The macros specified in the Code column of the following table are
277 defined for use as values of si_code that are signal-specific or non-
278 signal-specific reasons why the signal was generated.
279
280 Signal Code Reason
281 SIGILL ILL_ILLOPC Illegal opcode.
282 ILL_ILLOPN Illegal operand.
283 ILL_ILLADR Illegal addressing mode.
284 ILL_ILLTRP Illegal trap.
285 ILL_PRVOPC Privileged opcode.
286 ILL_PRVREG Privileged register.
287 ILL_COPROC Coprocessor error.
288 ILL_BADSTK Internal stack error.
289 SIGFPE FPE_INTDIV Integer divide by zero.
290 FPE_INTOVF Integer overflow.
291 FPE_FLTDIV Floating-point divide by zero.
292 FPE_FLTOVF Floating-point overflow.
293 FPE_FLTUND Floating-point underflow.
294 FPE_FLTRES Floating-point inexact result.
295 FPE_FLTINV Invalid floating-point operation.
296 FPE_FLTSUB Subscript out of range.
297 SIGSEGV SEGV_MAPERR Address not mapped to object.
298 SEGV_ACCERR Invalid permissions for mapped object.
299 SIGBUS BUS_ADRALN Invalid address alignment.
300 BUS_ADRERR Nonexistent physical address.
301 BUS_OBJERR Object-specific hardware error.
302 SIGTRAP TRAP_BRKPT Process breakpoint.
303 TRAP_TRACE Process trace trap.
304 SIGCHLD CLD_EXITED Child has exited.
305 CLD_KILLED Child has terminated abnormally and did
306 not create a core file.
307 CLD_DUMPED Child has terminated abnormally and cre‐
308 ated a core file.
309 CLD_TRAPPED Traced child has trapped.
310 CLD_STOPPED Child has stopped.
311 CLD_CONTINUED Stopped child has continued.
312 SIGPOLL POLL_IN Data input available.
313 POLL_OUT Output buffers available.
314 POLL_MSG Input message available.
315 POLL_ERR I/O error.
316 POLL_PRI High priority input available.
317 POLL_HUP Device disconnected.
318 Any SI_USER Signal sent by kill().
319 SI_QUEUE Signal sent by the sigqueue().
320 SI_TIMER Signal generated by expiration of a
321 timer set by timer_settime().
322 SI_ASYNCIO Signal generated by completion of an
323 asynchronous I/O request.
324 SI_MESGQ Signal generated by arrival of a message
325 on an empty message queue.
326
327 Implementations may support additional si_code values not included in
328 this list, may generate values included in this list under circum‐
329 stances other than those described in this list, and may contain exten‐
330 sions or limitations that prevent some values from being generated.
331 Implementations do not generate a different value from the ones
332 described in this list for circumstances described in this list.
333
334 In addition, the following signal-specific information shall be avail‐
335 able:
336
337 Signal Member Value
338 SIGILL void * si_addr Address of faulting instruction.
339 SIGFPE
340 SIGSEGV void * si_addr Address of faulting memory reference.
341 SIGBUS
342 SIGCHLD pid_t si_pid Child process ID.
343 int si_status Exit value or signal.
344 uid_t si_uid Real user ID of the process that sent the signal.
345 SIGPOLL long si_band Band event for POLL_IN, POLL_OUT, or POLL_MSG.
346
347 For some implementations, the value of si_addr may be inaccurate.
348
349 The following shall be declared as functions and may also be defined as
350 macros:
351
352
353 void (*bsd_signal(int, void (*)(int)))(int);
354
355
356 int kill(pid_t, int);
357
358
359 int killpg(pid_t, int);
360
361
362 int pthread_kill(pthread_t, int);
363 int pthread_sigmask(int, const sigset_t *, sigset_t *);
364
365 int raise(int);
366
367 int sigaction(int, const struct sigaction *restrict,
368 struct sigaction *restrict);
369 int sigaddset(sigset_t *, int);
370
371
372 int sigaltstack(const stack_t *restrict, stack_t *restrict);
373
374
375 int sigdelset(sigset_t *, int);
376 int sigemptyset(sigset_t *);
377 int sigfillset(sigset_t *);
378
379
380 int sighold(int);
381 int sigignore(int);
382 int siginterrupt(int, int);
383
384
385 int sigismember(const sigset_t *, int);
386
387 void (*signal(int, void (*)(int)))(int);
388
389 int sigpause(int);
390
391
392 int sigpending(sigset_t *);
393 int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict);
394
395
396 int sigqueue(pid_t, int, const union sigval);
397
398
399 int sigrelse(int);
400 void (*sigset(int, void (*)(int)))(int);
401
402
403 int sigsuspend(const sigset_t *);
404
405
406 int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict,
407 const struct timespec *restrict);
408
409
410 int sigwait(const sigset_t *restrict, int *restrict);
411
412
413 int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict);
414
415
416 Inclusion of the <signal.h> header may make visible all symbols from
417 the <time.h> header.
418
419 The following sections are informative.
420
422 None.
423
425 None.
426
428 None.
429
431 <errno.h>, <stropts.h>, <sys/types.h>, <time.h>, <ucontext.h>, the Sys‐
432 tem Interfaces volume of IEEE Std 1003.1-2001, alarm(), bsd_signal(),
433 ioctl(), kill(), killpg(), raise(), sigaction(), sigaddset(), sigalt‐
434 stack(), sigdelset(), sigemptyset(), sigfillset(), siginterrupt(),
435 sigismember(), signal(), sigpending(), sigprocmask(), sigqueue(), sig‐
436 suspend(), sigwaitinfo(), wait(), waitid()
437
439 Portions of this text are reprinted and reproduced in electronic form
440 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
441 -- Portable Operating System Interface (POSIX), The Open Group Base
442 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
443 Electrical and Electronics Engineers, Inc and The Open Group. In the
444 event of any discrepancy between this version and the original IEEE and
445 The Open Group Standard, the original IEEE and The Open Group Standard
446 is the referee document. The original Standard can be obtained online
447 at http://www.opengroup.org/unix/online.html .
448
449
450
451IEEE/The Open Group 2003 <signal.h>(0P)