signal.h(7POSIX)
β¨ PROLOG β¨
Ok bestie, real talk before we even get into it: 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 of Linux behavior), or the interface may not be implemented on Linux. π
π NAME π
So like, <signal.h> β signals. That's the whole name. Short, iconic, does exactly what it says on the tin. π
πΈ SYNOPSIS πΈ
#include <signal.h>
That's it. That's the whole vibe. Slap that include in and you're in business. π¦
π DESCRIPTION π
Okay so here's the thing, some of the functionality described on this reference page extends the ISO C standard. So if you want those extra symbols to even be visible in this header, your application shall define the appropriate feature test macro (see the System Interfaces volume of POSIX.1-2017, Section 2.2, The Compilation Environment). No macro, no symbols, no cap. π«
The Signal-Handling Macros π«Ά
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. (Yes that's a lot of requirements, they're just making sure you can't confuse these with a real function pointer, ok? π)
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 It Pulls In From Elsewhere π§
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 pthread_attr_t type as described in <sys/types.h>.
Types It Defines Itself β¨
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. (yes, even then. it's built different.)sigset_tβ Integer or structure type of an object used to represent sets of signals.pid_tβ As described in<sys/types.h>.
The sigevent Structure π
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.
And 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 π
The sigval union shall be defined as:
int sival_int Integer signal value.
void *sival_ptr Pointer signal value.
Realtime Signals, aka the Good Stuff π₯
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. (Yeah, read that again. They're macros but not necessarily constants. It's giving chaos but it's legal. π)
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 table below.
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.
The Signal Macros π
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.
Now, important lore drop: 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 the table).
The Signal Table π
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.
The Default Actions, Decoded π
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. π
The sigaction Structure π¦
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 bysa_handlerandsa_sigactionmay overlap, and a conforming application shall not use both simultaneously. Pick a lane bestie, it's one or the other. π
Mask-Modifying Macros π
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.
Symbolic Constants, The Whole Squad β¨
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.
One Last Type π
The <signal.h> header shall define the mcontext_t type through typedef.
and that's part 1, bestie β hold tight, there's more coming π«Ά
okay so the <signal.h> header is also gonna define the ucontext_t type as a struct, and it shall 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.
next up, the <signal.h> header shall define the stack_t type as a struct, and it shall include at least these members:
void *ss_spβ Stack base or pointer.size_t ss_sizeβ Stack size.int ss_flagsβ Flags.
and the <signal.h> header shall define the siginfo_t type as a struct, which shall include at least these members:
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 forSIGPOLL.union sigval si_valueβ Signal value.
The <signal.h> header shall define the symbolic constants in the Code column of the following table for use as values of si_code that are signal-specific or non-signal-specific reasons why the signal was generated. periodt, every single one is here:
SIGILLβ illegal opcode energy, we love a dramatic crash π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β math said nope, floating-point drama incoming π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β the classic segmentation fault, main character of bad vibes β¨SEGV_MAPERRβ Address not mapped to object.SEGV_ACCERRβ Invalid permissions for mapped object.
SIGBUSβ bus error, lowkey chaotic π¦BUS_ADRALNβ Invalid address alignment.BUS_ADRERRβ Nonexistent physical address.BUS_OBJERRβ Object-specific hardware error.
SIGTRAPβ trap queen, literally πTRAP_BRKPTβ Process breakpoint.TRAP_TRACEβ Process trace trap.
SIGCHLDβ child process updates, the group chat is active πΌ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 events, very I/O coded π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β these are the non-signal-specific ones, they can show up with any signal, fr fr π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.
and that's a wrap on that table, bestie! π
Now, real talk: implementations can be extra. They may support additional si_code values not included in the list above, may generate values included in this list under circumstances other than those described in this list, and may contain extensions or limitations that prevent some values from being generated. But here's the tea: implementations do not generate a different value from the ones described in this list for circumstances described in this list. Periodt. β¨
Also, these signal-specific deets shall be available:
SIGILL/SIGFPEβ member:void * si_addr; value: Address of faulting instruction. πSIGSEGV/SIGBUSβ member:void * si_addr; value: Address of faulting memory reference. π«SIGCHLDβ- member:
pid_t si_pid; value: Child process ID. - member:
int si_status; value: Ifsi_codeis equal toCLD_EXITED, thensi_statusholds the exit value of the process; otherwise, it is 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. - member:
uid_t si_uid; value: Real user ID of the process that sent the signal.
- member:
SIGPOLLβ member:long si_band; value: Band event forPOLL_IN,POLL_OUT, orPOLL_MSG.
For some implementations, the value of si_addr may be inaccurate. π
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. π
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);
Inclusion of the <signal.h> header may make visible all symbols from the <time.h> header. π
The following sections are informative. π
β¨ APPLICATION USAGE β¨
So if your system isn't supporting 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. But on XSI-conforming systems? They're also valid for all si_code values less than or equal to 0. However β and this is the messy part β it's 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 tell whether si_pid and si_uid are valid. π
β¨ RATIONALE β¨
None. That's it. Nothing. Nada. π
β¨ FUTURE DIRECTIONS β¨
The SIGPOLL and SIGPROF signals may be removed in a future version. π
β¨ 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, 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 β¨
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 .
This gem is from IEEE/The Open Group, 2017, and it's the signal.h(7POSIX) page. Stay slaying, bestie! πβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms