C标准库参考指南(9)signal.h

时间:2022-12-10 19:09:55

9. signal.h

头文件signal处理程序运行时产生的信号的方法。

宏:

SIG_DFL

SIG_ERR

SIG_IGN

SIGABRT

SIGFPE

SIGILL

SIGINT

SIGSEGV

SIGTERM

函数:

signal();

raise();

变量:

typedef sig_atomic_t

9.1. 变量和定义

类型sig_atomic_t就是int,作为signal函数的handler中的变量。SIG_宏用于signal函数中用于定义信号函数。

SIG_DFL   默认handler。

SIG_ERR   表示错误信号。

SIG_IGN   忽略信号。

SIG宏代表下列情况下的信号编号。

SIGABRT   异常终止(由abort函数产生)。

SIGFPE   浮点错误(由零除运行、不合理操作产生)。

SIGILL   非法操作(指令)。

SIGINT   交互信号(比如我们熟悉的Ctrl-C)。

SIGSEGV   非法存储访问(段错误,内存错误)。

SIGTERM   终止请求。

9.2. signal

声明:

void (*signal(int sig, void (*func)(int)))(int);

该函数管理一个信号应该如何被操控。sig代表与SIG宏相容的信号编号。func函数会在信号产生时被调用。如果函数是SIG_DFL,则调用默认的handler。如果func是SIG_IGN,则信号被忽略。如果func指向一个函数,那么当检测到一个信号并执行默认handler时,该函数会被调用。函数必须携带一个int参数代表信号编号。函数可能被return,abort,exit,或者longjmp终止。当函数终止时,程序继续从中断处执行(除非是结果未定义的信号SIGFPE)。

如果信号调用成功,则返回指向之前特定信号类型的handler的指针。如果信号调用失败,则返回SIG_ERR并且将errno设置一个合理值。



http://t.163.com/event/info/eventId/977421684245214597
http://t.163.com/event/info/eventId/2135103686680747640
http://t.163.com/event/info/eventId/-5676406222372852395
http://t.163.com/event/info/eventId/3130423446132204561
http://t.163.com/event/info/eventId/921182335946111515
http://t.163.com/event/info/eventId/-6655012937212396254
http://t.163.com/event/info/eventId/83337673422867535
http://t.163.com/event/info/eventId/4462382249026691460
http://t.163.com/event/info/eventId/555531106596934231
http://t.163.com/event/info/eventId/3108590180151831206
http://t.163.com/event/info/eventId/-3607869766369818034
http://t.163.com/event/info/eventId/-1604842125369832887
http://t.163.com/event/info/eventId/-7648301737856262751
http://t.163.com/event/info/eventId/-8474502621039053364
http://t.163.com/event/info/eventId/-1224705752558931079
http://t.163.com/event/info/eventId/5374752731193395722
http://t.163.com/event/info/eventId/-310359497326341829
http://t.163.com/event/info/eventId/-8464605211056170535
http://t.163.com/event/info/eventId/3528517483339984404
http://t.163.com/event/info/eventId/-7298563176060420579
http://t.163.com/event/info/eventId/-1910466885403418656
http://t.163.com/event/info/eventId/8829288207429993785
http://t.163.com/event/info/eventId/-4175869309094398667
http://t.163.com/event/info/eventId/-5616153410872742366
http://t.163.com/event/info/eventId/4906779338840954829
http://t.163.com/event/info/eventId/2581067874494105994
http://t.163.com/event/info/eventId/3760377744977204271
http://t.163.com/event/info/eventId/336164657999119209
http://t.163.com/event/info/eventId/-8361892863841984310
http://t.163.com/event/info/eventId/-8049172220116908142
http://www.douguo.com/cookbook/363311.html
http://www.douguo.com/cookbook/363322.html
http://www.douguo.com/cookbook/363335.html
http://www.douguo.com/cookbook/363350.html
http://www.douguo.com/cookbook/363384.html
http://www.douguo.com/cookbook/363419.html
http://www.douguo.com/cookbook/363456.html
http://www.douguo.com/cookbook/363478.html
http://www.douguo.com/cookbook/363500.html
http://www.douguo.com/cookbook/363514.html
http://www.douguo.com/cookbook/363529.html
http://www.douguo.com/cookbook/363542.html
http://www.douguo.com/cookbook/363571.html
http://www.douguo.com/cookbook/363603.html
http://www.douguo.com/cookbook/363653.html
http://www.douguo.com/cookbook/363705.html
http://www.douguo.com/cookbook/363718.html
http://www.douguo.com/cookbook/363752.html
http://www.douguo.com/cookbook/363812.html
http://www.douguo.com/cookbook/363826.html
http://www.douguo.com/cookbook/363851.html
http://www.douguo.com/cookbook/363877.html
http://www.douguo.com/cookbook/363895.html
http://www.douguo.com/cookbook/363906.html
http://www.douguo.com/cookbook/363929.html
http://www.douguo.com/cookbook/363942.html
http://www.douguo.com/cookbook/363963.html
http://www.douguo.com/cookbook/363981.html
http://www.douguo.com/cookbook/364001.html
http://www.douguo.com/cookbook/364015.html
http://j.renren.com/album/1308201601183271626
http://j.renren.com/album/1308201602019237138
http://j.renren.com/album/1308201602449534020
http://j.renren.com/album/1308201604515949943
http://j.renren.com/album/1308201606343049288
http://j.renren.com/album/1308201607495316799
http://j.renren.com/album/1308201608396987696
http://j.renren.com/album/1308201609293473297
http://j.renren.com/album/1308201610106812885
http://j.renren.com/album/1308201611134451350