signal.h(0P)
๐ PROLOG ๐
okay bestie, quick heads-up before we dive in: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details), or the interface may not be implemented on Linux. no cap. ๐ซถ
โจ NAME โจ
signal.h โ signals. it's giving the header that handles all the signal drama. ๐
๐ SYNOPSIS ๐
#include <signal.h>
๐ฆ DESCRIPTION ๐ฆ
Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature test macro (see the System Interfaces volume of POSIX.1โ2017, Section 2.2, The Compilation Environment) to enable the visibility of these symbols in this header.
๐ Macros that go brrr
The <signal.h> header shall define the following macros, which shall expand to constant expressions with distinct values that have a type compatible with the second argument to, and the return value of, the signal() function, and whose values shall compare unequal to the address of any declarable function. periodt.
SIG_DFLโ Request for default signal handling.SIG_ERRโ Return value fromsignal()in case of error.SIG_HOLDโ Request that signal be held.SIG_IGNโ Request that signal be ignored.
๐ Types, bestie
The <signal.h> header shall define the pthread_t, size_t, and uid_t types as described in <sys/types.h>.
The <signal.h> header shall define the timespec structure as described in <time.h>.
The <signal.h> header shall define the following data types:
sig_atomic_tโ Possibly volatile-qualified integer type of an object that can be accessed as an atomic entity, even in the presence of asynchronous interrupts.sigset_tโ Integer or structure type of an object used to represent sets of signals.pid_tโ As described in<sys/types.h>.
The <signal.h> header shall define the pthread_attr_t type as described in <sys/types.h>.
๐ง sigevent and sigval
The <signal.h> header shall define the sigevent structure, which shall include at least the following members:
int sigev_notify Notification type.
int sigev_signo Signal number.
union sigval sigev_value Signal value.
void (*sigev_notify_function)(union sigval)
Notification function.
pthread_attr_t *sigev_notify_attributes Notification attributes.
The <signal.h> header shall define the following symbolic constants for the values of sigev_notify:
SIGEV_NONEโ No asynchronous notification is delivered when the event of interest occurs.SIGEV_SIGNALโ A queued signal, with an application-defined value, is generated when the event of interest occurs.SIGEV_THREADโ A notification function is called to perform notification.
The sigval union shall be defined as:
int sival_int Integer signal value.
void *sival_ptr Pointer signal value.
๐ฅ SIGRTMIN / SIGRTMAX
The <signal.h> header shall declare the SIGRTMIN and SIGRTMAX macros, which shall expand to positive integer expressions with type int, but which need not be constant expressions. These macros specify a range of signal numbers that are reserved for application use and for which the realtime signal behavior specified in this volume of POSIX.1โ2017 is supported. The signal numbers in this range do not overlap any of the signals specified in the following signal list.
The range SIGRTMIN through SIGRTMAX inclusive shall include at least {RTSIG_MAX} signal numbers.
It is implementation-defined whether realtime signal behavior is supported for other signals.
๐ Signal names, the iconic list
The <signal.h> header shall define the following macros that are used to refer to the signals that occur in the system. Signals defined here begin with the letters SIG followed by an uppercase letter. The macros shall expand to positive integer constant expressions with type int and distinct values. The value 0 is reserved for use as the null signal (see kill()). Additional implementation-defined signals may occur in the system.
The ISO C standard only requires the signal names SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, and SIGTERM to be defined. An implementation need not generate any of these six signals, except as a result of explicit use of interfaces that generate signals, such as raise(), kill(), the General Terminal Interface (see Section 11.1.9, Special Characters), and the kill utility, unless otherwise stated (see, for example, the System Interfaces volume of POSIX.1โ2017, Section 2.8.3.3, Memory Protection).
The following signals shall be supported on all implementations (default actions are explained below this signal list):
SIGABRTโ default action:Aโ Process abort signal.SIGALRMโ default action:Tโ Alarm clock.SIGBUSโ default action:Aโ Access to an undefined portion of a memory object.SIGCHLDโ default action:Iโ Child process terminated, stopped, or continued.SIGCONTโ default action:Cโ Continue executing, if stopped.SIGFPEโ default action:Aโ Erroneous arithmetic operation.SIGHUPโ default action:Tโ Hangup.SIGILLโ default action:Aโ Illegal instruction.SIGINTโ default action:Tโ Terminal interrupt signal.SIGKILLโ default action:Tโ Kill (cannot be caught or ignored).SIGPIPEโ default action:Tโ Write on a pipe with no one to read it.SIGQUITโ default action:Aโ Terminal quit signal.SIGSEGVโ default action:Aโ Invalid memory reference.SIGSTOPโ default action:Sโ Stop executing (cannot be caught or ignored).SIGTERMโ default action:Tโ Termination signal.SIGTSTPโ default action:Sโ Terminal stop signal.SIGTTINโ default action:Sโ Background process attempting read.SIGTTOUโ default action:Sโ Background process attempting write.SIGUSR1โ default action:Tโ User-defined signal 1.SIGUSR2โ default action:Tโ User-defined signal 2.SIGPOLLโ default action:Tโ Pollable event.SIGPROFโ default action:Tโ Profiling timer expired.SIGSYSโ default action:Aโ Bad system call.SIGTRAPโ default action:Aโ Trace/breakpoint trap.SIGURGโ default action:Iโ High bandwidth data is available at a socket.SIGVTALRMโ default action:Tโ Virtual timer expired.SIGXCPUโ default action:Aโ CPU time limit exceeded.SIGXFSZโ default action:Aโ File size limit exceeded.
๐ซถ Default actions
The default actions are as follows:
Tโ Abnormal termination of the process.Aโ Abnormal termination of the process with additional actions.Iโ Ignore the signal.Sโ Stop the process.Cโ Continue the process, if it is stopped; otherwise, ignore the signal.
The effects on the process in each case are described in the System Interfaces volume of POSIX.1โ2017, Section 2.4.3, Signal Actions.
๐ญ sigaction struct
The <signal.h> header shall declare the sigaction structure, which shall include at least the following members:
void (*sa_handler)(int) Pointer to a signal-catching function
or one of the SIG_IGN or SIG_DFL.
sigset_t sa_mask Set of signals to be blocked during execution
of the signal handling function.
int sa_flags Special flags.
void (*sa_sigaction)(int, siginfo_t *, void *)
Pointer to a signal-catching function.
The storage occupied by sa_handler and sa_sigaction may overlap, and a conforming application shall not use both simultaneously.
๐ธ SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK
The <signal.h> header shall define the following macros which shall expand to integer constant expressions that need not be usable in #if preprocessing directives:
SIG_BLOCKโ The resulting set is the union of the current set and the signal set pointed to by the argument set.SIG_UNBLOCKโ The resulting set is the intersection of the current set and the complement of the signal set pointed to by the argument set.SIG_SETMASKโ The resulting set is the signal set pointed to by the argument set.
๐ SA_* and SS_* and stack constants
The <signal.h> header shall also define the following symbolic constants:
SA_NOCLDSTOPโ Do not generateSIGCHLDwhen children stop or stopped children continue.SA_ONSTACKโ Causes signal delivery to occur on an alternate stack.SA_RESETHANDโ Causes signal dispositions to be set toSIG_DFLon entry to signal handlers.SA_RESTARTโ Causes certain functions to become restartable.SA_SIGINFOโ Causes extra information to be passed to signal handlers at the time of receipt of a signal.SA_NOCLDWAITโ Causes implementations not to create zombie processes or status information on child termination. Seesigaction().SA_NODEFERโ Causes signal not to be automatically blocked on entry to signal handler.SS_ONSTACKโ Process is executing on an alternate signal stack.SS_DISABLEโ Alternate signal stack is disabled.MINSIGSTKSZโ Minimum stack size for a signal handler.SIGSTKSZโ Default size in bytes for the alternate signal stack.
โญ mcontext_t
The <signal.h> header shall define the mcontext_t type through typedef.
okay so bestie, the <signal.h> header is still going off, and now it's defining ucontext_t as a structure that has to include at least these members, no cap:
ucontext_t *uc_link Pointer to the context that is resumed
when this context returns.
sigset_t uc_sigmask The set of signals that are blocked when this
context is active.
stack_t uc_stack The stack used by this context.
mcontext_t uc_mcontext A machine-specific representation of the saved
context.
then it also defines stack_t as a structure, which shall include at least these members, periodt:
void *ss_sp Stack base or pointer.
size_t ss_size Stack size.
int ss_flags Flags.
and siginfo_t? also a structure, at least these members, iykyk:
int si_signo Signal number.
int si_code Signal code.
int si_errno If non-zero, an errno value associated with
this signal, as described in <errno.h>.
pid_t si_pid Sending process ID.
uid_t si_uid Real user ID of sending process.
void *si_addr Address of faulting instruction.
int si_status Exit value or signal.
long si_band Band event for SIGPOLL.
union sigval si_value Signal value.
so like, the header also defines the symbolic constants in the Code column of the table below, and you use them as values of si_code โ they're the reasons why the signal was generated, either signal-specific or non-signal-specific. let's break it down ๐
SIGILL ๐
ILL_ILLOPCโ Illegal opcode.ILL_ILLOPNโ Illegal operand.ILL_ILLADRโ Illegal addressing mode.ILL_ILLTRPโ Illegal trap.ILL_PRVOPCโ Privileged opcode.ILL_PRVREGโ Privileged register.ILL_COPROCโ Coprocessor error.ILL_BADSTKโ Internal stack error.
SIGFPE ๐งฎ
FPE_INTDIVโ Integer divide by zero.FPE_INTOVFโ Integer overflow.FPE_FLTDIVโ Floating-point divide by zero.FPE_FLTOVFโ Floating-point overflow.FPE_FLTUNDโ Floating-point underflow.FPE_FLTRESโ Floating-point inexact result.FPE_FLTINVโ Invalid floating-point operation.FPE_FLTSUBโ Subscript out of range.
SIGSEGV ๐ซ
SEGV_MAPERRโ Address not mapped to object.SEGV_ACCERRโ Invalid permissions for mapped object.
SIGBUS ๐
BUS_ADRALNโ Invalid address alignment.BUS_ADRERRโ Nonexistent physical address.BUS_OBJERRโ Object-specific hardware error.
SIGTRAP ๐ชค
TRAP_BRKPTโ Process breakpoint.TRAP_TRACEโ Process trace trap.
SIGCHLD ๐ถ
CLD_EXITEDโ Child has exited.CLD_KILLEDโ Child has terminated abnormally and did not create a core file.CLD_DUMPEDโ Child has terminated abnormally and created a core file.CLD_TRAPPEDโ Traced child has trapped.CLD_STOPPEDโ Child has stopped.CLD_CONTINUEDโ Stopped child has continued.
SIGPOLL ๐ก
POLL_INโ Data input available.POLL_OUTโ Output buffers available.POLL_MSGโ Input message available.POLL_ERRโ I/O error.POLL_PRIโ High priority input available.POLL_HUPโ Device disconnected.
Any โจ
SI_USERโ Signal sent bykill().SI_QUEUEโ Signal sent bysigqueue().SI_TIMERโ Signal generated by expiration of a timer set bytimer_settime().SI_ASYNCIOโ Signal generated by completion of an asynchronous I/O request.SI_MESGQโ Signal generated by arrival of a message on an empty message queue.
Implementations may support extra si_code values that are not in that list, and they may also generate values that are in the list under circumstances other than the ones described there. They may also have extensions or limitations that stop some of those values from ever being generated. But โ and this is the important bit โ implementations do not generate a different value from the ones described in that list for the circumstances described in that list. No cap. ๐
On top of all that, the following signal-specific info has to be available too:
SIGILL,SIGFPEvoid * si_addrโ the address of the faulting instruction.
SIGSEGV,SIGBUSvoid * si_addrโ the address of the faulting memory reference.
SIGCHLDpid_t si_pidโ the child process ID.int si_statusโ ifsi_codeis equal toCLD_EXITED, thensi_statusholds the exit value of the process; otherwise it's equal to the signal that caused the process to change state. The exit value insi_statusshall be equal to the full exit value (that is, the value passed to_exit(),_Exit(), orexit(), or returned frommain()); it shall not be limited to the least significant eight bits of the value.uid_t si_uidโ the real user ID of the process that sent the signal.
SIGPOLLlong si_bandโ the band event forPOLL_IN,POLL_OUT, orPOLL_MSG.
Heads up bestie: for some implementations, the value of si_addr may be inaccurate. It's giving "close enough" energy. ๐ญ
โจ THE FUNCTIONS โจ
The following shall be declared as functions, and they may also be defined as macros. Function prototypes shall be provided. Yes, all of them. Every single one. We're not skipping. ๐ซถ
int kill(pid_t, int);
int killpg(pid_t, int);
void psiginfo(const siginfo_t *, const char *);
void psignal(int, const char *);
int pthread_kill(pthread_t, int);
int pthread_sigmask(int, const sigset_t *restrict,
sigset_t *restrict);
int raise(int);
int sigaction(int, const struct sigaction *restrict,
struct sigaction *restrict);
int sigaddset(sigset_t *, int);
int sigaltstack(const stack_t *restrict, stack_t *restrict);
int sigdelset(sigset_t *, int);
int sigemptyset(sigset_t *);
int sigfillset(sigset_t *);
int sighold(int);
int sigignore(int);
int siginterrupt(int, int);
int sigismember(const sigset_t *, int);
void (*signal(int, void (*)(int)))(int);
int sigpause(int);
int sigpending(sigset_t *);
int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict);
int sigqueue(pid_t, int, union sigval);
int sigrelse(int);
void (*sigset(int, void (*)(int)))(int);
int sigsuspend(const sigset_t *);
int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict,
const struct timespec *restrict);
int sigwait(const sigset_t *restrict, int *restrict);
int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict);
Also, lowkey iconic behaviour: including the <signal.h> header may make visible all symbols from the <time.h> header. Surprise crossover episode. โญ
The following sections are informative. (That's fancy speak for "this part is the tea, not the rules." ๐)
๐ธ APPLICATION USAGE ๐ธ
Okay so listen. On systems that do not support the XSI option, the si_pid and si_uid members of siginfo_t are only required to be valid when si_code is SI_USER or SI_QUEUE.
On XSI-conforming systems, they're also valid for all si_code values less than or equal to 0. But plot twist: it is unspecified whether SI_USER and SI_QUEUE have values less than or equal to zero. So XSI applications should check whether si_code has the value SI_USER or SI_QUEUE, or is less than or equal to 0, to figure out whether si_pid and si_uid are valid. Check all the boxes, bestie, don't get caught lacking. ๐
๐ RATIONALE ๐
None.
(Not me, the actual manpage being like "no thoughts, head empty" about this one. Respect. ๐)
๐ฎ FUTURE DIRECTIONS ๐ฎ
The SIGPOLL and SIGPROF signals may be removed in a future version. So likeโฆ don't build your whole personality around them, fr fr. ๐
๐ SEE ALSO ๐
<errno.h>,<stropts.h>,<sys_types.h>,<time.h>
The System Interfaces volume of POSIX.1โ2017, Section 2.2, The Compilation Environment, and then the whole squad: alarm(), ioctl(), kill(), killpg(), psiginfo(), pthread_kill(), pthread_sigmask(), raise(), sigaction(), sigaddset(), sigaltstack(), sigdelset(), sigemptyset(), sigfillset(), sighold(), siginterrupt(), sigismember(), signal(), sigpending(), sigqueue(), sigsuspend(), sigtimedwait(), sigwait(), timer_create(), wait(), waitid()
The Shell and Utilities volume of POSIX.1โ2017: kill
๐ COPYRIGHT ๐
Okay legal besties, this next part is sacred text and we do not touch it. Copying it exactly, character for character, periodt. โจ
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! ๐ฆ๐ This one came to you from IEEE/The Open Group, dated 2017, and it lives at signal.h(0P) โ go forth and signal responsibly, you absolute icon. ๐๐ธ
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms