Clever Geek Handbook
📜 ⬆️ ⬇️

signal.h

signal.h is the header file defined in the standard C library to indicate how the program processes signals during its execution. A signal can be either synchronous using the raise() call, or asynchronous.

Standard library
C programming language
  • assert.h
  • complex.h (C99)
  • ctype.h
  • errno.h
  • fenv.h (C99)
  • float.h
  • inttypes.h (C99)
  • iso646.h
  • limits.h
  • locale.h
  • math.h
  • setjmp.h
  • signal.h
  • stdalign.h (C11)
  • stdarg.h
  • stdatomic.h (C11)
  • stdbool.h (C99)
  • stddef.h
  • stdint.h (C99)
  • stdio.h
  • stdlib.h
  • stdnoreturn.h (C11)
  • string.h
  • tgmath.h
  • threads.h (C11)
  • time.h
  • uchar.h (C11)
  • wchar.h
  • wctype.h

Each implementation determines which signal generates and determines their generation.

This part of the library is used to intercept signals - assigning a handler to a specific signal.

A signal handler can only call the following functions: _exit() , _Exit() , abort() , raise() (only if the handler is not called by the abort or raise functions). Calling other library functions leads to undefined behavior, although such calls can be resolved by individual implementations, for example, posix has a list of async-signal-safe functions.

Content

Data Types

The standard declares the sig_atomic_t data sig_atomic_t , access to which is atomic , even in the presence of asynchronous interrupts . [one]

Macros

The standard declares macros SIG_DFL , SIG_ERR , SIG_IGN , which are used as arguments and return value for the signal() function. [1] The SIG_DFL macro is used to set the default behavior for the selected signal, SIG_IGN is used to ignore the signal, and SIG_ERR is used as a return value indicating an error.

In addition, the standard defines the following types of signals: [1]

ConstantValue
SigintReceiving an Interactive Signal
SigillInvalid instruction
SIGABRTAbnormal program termination that may be caused by abort()
SigfpeErroneous arithmetic operation, such as division by zero or overflow
SigsegvInvalid access to an object in memory
SigtermTermination Request

and allows others that are platform dependent. When the program starts, part of the signals may be ignored; for the other part, the default behavior is determined.

Functions

The standard declares the following functions:

  #include <signal.h> 
 void ( * signal ( int sig , void ( * func ) ( int ))) ( int );
 int raise ( int sig );

The signal function sets the func handler for the sig signal. func can take SIG_IGN and SIG_DFL as arguments. If successful, the function returns the old signal handler; otherwise, SIG_ERR .

If the handler returns control when the signal type is SIGILL , SIGFPE , SIGSEGV or others associated with runtime errors, the program behavior is undefined. In addition, if the handler was not called using abort or raise, it can only change variables of type volatile sig_atomic_t .

The raise function generates a sig signal. [one]

Methods

  • int raise(int sig) . Artificially triggers a signal.
  • psignal (int sig, const char *s) , prints to stderr a string containing the signal number. Used in 4.3BSD , Solaris, and Linux , but not specified in POSIX , the standard C library and SUS . On the same systems, string.h contains the non-standard strsignal (int sig) , which works similarly to strerror .
  • void* signal(int sig, void (*func)(int)) designates the action taken when the program receives the sig signal. If func is SIG_DFL, then the default processing for the specified signal occurs. If func is SIG_IGN, then the signal is ignored. In other cases, func points to the called function of the signal handler when the signal is received. The func function may end with a return operation or a call to the self-completion, exit, or transition functions.

Constant Members

ConstantValueStandards
SighupHang upPosix
SigintInterruptAnsi
SIGQUITOutputPosix
SigillInvalid instructionAnsi
SIGABRTSelf stopAnsi
SIGTRAPEvent interceptionPosix
SigiotI / O interception4.2 BSD
SigemtEmulation capture4.2 BSD
SigfpeFloating point exceptionAnsi
SigkillCaptured Termination SignalPosix
SigbusBus error4.2 BSD
SigsegvSegmentation disorderAnsi
SigsInvalid argument to system call4.2 BSD
SigpipeChannel violationPosix
SIGALRMExpiration timePosix
SigtermCompletionAnsi
SIGUSR1Custom Signal 1Posix
SIGUSR2Custom Signal 2Posix
SigchldChange the status of a child processPosix
SigcldSimilar to SIGCHLDSystem v
SigpwrRestart after a power problemSystem v
SIGXCPUCPU time limitPosix

Notes

  1. ↑ 1 2 3 4 ISO / IEC 9899: TC3 7.14

Links

  • signal.h - Basic Definitions, The Single UNIX® Specification , Issue 7 by The Open Group
  • Dinkumware Guide on signal.h
  • XGC Guide to signal.h
Source - https://ru.wikipedia.org/w/index.php?title=Signal.h&oldid=92691758


More articles:

  • Yanban
  • Onohoy
  • Uyghur Khazar Origin
  • Arseniev, Vladimir Romanovich
  • Ob-Irtysh Region
  • Keller, Homer
  • Cairo (Governorate)
  • Baikonurov, Omirkhan Aimagambetovich
  • Dmitriev-Orenburg, Nikolai Dmitrievich
  • Multiple Value Function

All articles

Clever Geek | 2019