sig_atomic_t

Defined in header <signal.h>
typedef /* unspecified */ sig_atomic_t;

An integer type which can be accessed as an atomic entity even in the presence of asynchronous interrupts made by signals.

Example

#include <signal.h>
#include <stdio.h>
 
volatile sig_atomic_t gSignalStatus = 0;
 
void signal_handler(int signal)
{
    gSignalStatus = signal;
}
 
int main(void)
{
    /* Install a signal handler. */
    signal(SIGINT, signal_handler);
 
    printf("SignalValue:   %d\n", gSignalStatus);
    printf("Sending signal %d\n", SIGINT);
    raise(SIGINT);
    printf("SignalValue:   %d\n", gSignalStatus);
}

Possible output:

SignalValue:   0
Sending signal 2
SignalValue:   2

References

  • C11 standard (ISO/IEC 9899:2011):
    • 7.14/2 Signal handling <signal.h> (p: 265)
  • C99 standard (ISO/IEC 9899:1999):
    • 7.14/2 Signal handling <signal.h> (p: 246)
  • C89/C90 standard (ISO/IEC 9899:1990):
    • 4.7 SIGNAL HANDLING <signal.h>

See also

sets a signal handler for particular signal
(function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/program/sig_atomic_t