C++官网参考链接:https://cplusplus.com/reference/csignal/
头文件
<csignal> (signal.h)
处理信号的C库
有些运行环境使用信号将某些事件通知正在运行的进程。这些事件可能与程序代码执行的错误有关,如错误的算术操作,也可能与异常情况有关,如中断程序的请求。
信号通常表示程序被请求终止或发生不可恢复错误的情况,因此处理信号允许执行终止前清理操作或尝试以某种方式从错误中恢复。
并非所有运行环境都需要在标准C库中为其设计的情况下生成自动信号,其他一些环境不仅生成这些信号,还生成许多更特定的信号。但在任何情况下,通过调用raise函数显式生成的所有信号都被传递给相应的信号处理程序。
函数
signal Set function to handle signal (function) (设置处理信号的函数(函数))
raise Generates a signal (function) (生成一个信号(函数))
类型
sig_atomic_t Integral type (type) (整数类型(类型))
宏常量
type | macro | signal(信号) |
---|---|---|
int (signals) |
SIGABRT | (Signal Abort) Abnormal termination, such as is initiated by the abort function.((信号终止)异常终止,例如由abort函数发起的终止。) |
SIGFPE | (Signal Floating-Point Exception) Erroneous arithmetic operation, such as zero divide or an operation resulting in overflow (not necessarily with a floating-point operation).((信号浮点异常)错误的算术操作,例如除0或导致上溢的操作(不一定是浮点操作)。) | |
SIGILL | (Signal Illegal Instruction) Invalid function image, such as an illegal instruction. This is generally due to a corruption in the code or to an attempt to execute data.((信号非法指令)无效的函数映像,如非法指令。这通常是由于代码损坏或试图执行数据。) | |
SIGINT | (Signal Interrupt) Interactive attention signal. Generally generated by the application user.((信号中断)交互性注意信号。一般由应用程序用户生成。) | |
SIGSEGV | (Signal Segmentation Violation) Invalid access to storage: When a program tries to read or write outside the memory it has allocated.((信号分段违规)对存储的无效访问:当程序试图读或写它已经分配的内存之外。) | |
SIGTERM | (Signal Terminate) Termination request sent to program.((信号终止)终止请求发送到程序。) | |
functions (handlers) | SIG_DFL | Default handling: The signal is handled by the default action for that particular signal.(默认处理:该信号由该特定信号的默认操作处理。) |
SIG_IGN | Ignore Signal: The signal is ignored.(忽略信号:信号被忽略。) | |
SIG_ERR | Special return value indicating failure.(指示失败的特殊返回值。) |
有关更多信息,请参见函数signal。
本文含有隐藏内容,请 开通VIP 后查看