1. 程式人生 > >C標準庫參考指南(9)signal.h

C標準庫參考指南(9)signal.h

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