Latest web development tutorials

C standard library - <signal.h>

Brief introduction

signal.h header file defines a variable type sig_atomic_t,two function calls and some macros to handle different signals during program execution reports.

Library variants

Here is a variable type defined in the header file signal.h:

序号变量 & 描述
1sig_atomic_t
这是int类型,在信号处理程序中作为变量使用。它是一个对象的整数类型,该对象可以作为一个原子实体访问,即使存在异步信号时,该对象可以作为一个原子实体访问。

Macro library

The following is a macro defined in the header file signal.h These macros will be used in the following two functions.SIG_ macro function together with the signal function to define the signal.

序号宏 & 描述
1 SIG_DFL
默认的信号处理程序。
2 SIG_ERR
表示一个信号错误。
3 SIG_IGN
忽视信号。

SIG macro is used to indicate the following conditions of the letter number:

序号宏 & 描述
1 SIGABRT
程序异常终止。
2 SIGFPE
算术运算出错,如除数为 0 或溢出。
3 SIGILL
非法函数映象,如非法指令。
4 SIGINT
中断信号,如 ctrl-C。
5 SIGSEGV
非法访问存储器,如访问不存在的内存单元。
6 SIGTERM
发送给本程序的终止请求信号。

Library Functions

Here is a function defined in the header file signal.h:

序号函数 & 描述
1 void (*signal(int sig, void (*func)(int)))(int)
该函数设置一个函数来处理信号,即信号处理程序。
2 int raise(int sig)
该函数会促使生成信号sig。sig 参数与 SIG 宏兼容。