第129页 | The C Programming Language | 阅读 ‧ 电子书库

同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库

B.9 Signals: <signal.h>

The header <signal.h> provides facilities for handling exceptional conditions that arise during execution, such as an interrupt signal from an external source or an error in execution.

 

void (*signal(int sig, void (*handler)(int)))(int)

signal determines how subsequent signals will be handled. If handler is SIG_DFL, the implementation-defined default behavior is used, if it is SIG_IGN, the signal is ignored; otherwise, the function pointed to by handler will be called, with the argument of the type of signal. Valid signals include

 

SIGABRTabnormal termination, e.g., from abort

SIGFPE arithmetic error, e.g., zero divide or overflow

SIGILL illegal function image, e.g., illegal instruction

SIGINT interactive attention, e.g., interrupt

SIGSEGVillegal storage access, e.g., access outside memory limits

SIGTERM  termination request sent to this program

signal returns the previous value of handler for the specific signal, or SIG_ERR if an error occurs.

When a signal sig subsequently occurs, the signal is restored to its default behavior; then the signal-handler function is called, as if by (*handler)(sig). If the handler returns, execution will resume where it was when the signal occurred.

The initial state of signals is implementation-defined.

 

int raise(int sig)

raise sends the signal sig to the program; it returns non-zero if unsuccessful.

请支持我们,让我们可以支付服务器费用。
使用微信支付打赏


上一页 · 目录下一页


下载 · 书页 · 阅读 ‧ 电子书库