第六章學(xué)習(xí)心得
知識(shí)點(diǎn)歸納

信號(hào)和信號(hào)處理;
信號(hào)和中斷的統(tǒng)一處理
將信號(hào)視為進(jìn)程中斷,將進(jìn)程從正常執(zhí)行轉(zhuǎn)移到信號(hào)處理
信號(hào)的來(lái)源,包 括來(lái)自硬件、異常和其他進(jìn)程的信號(hào)
信號(hào)在Unix/Linux中的常見(jiàn)用法
Unix/Linux中的信號(hào)處理
信號(hào)類(lèi)型
信號(hào)向量位
信號(hào)掩碼位
進(jìn)程 PROC結(jié)構(gòu)體中的信號(hào)處理程序
信號(hào)處理步驟
Unix/Linux支持31種不同的信號(hào),每種信號(hào)在signal.h文件中都有定義。
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#dpfine STGTTTN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGPOLL 29
#define SIGPWR 30
#define SIGSYS 31
問(wèn)題與解決思路

這應(yīng)該和信號(hào)處理的具體實(shí)現(xiàn)有關(guān),其數(shù)據(jù)結(jié)構(gòu)是位圖,而不是鏈表或者數(shù)組
當(dāng)一個(gè)信號(hào)產(chǎn)生時(shí),對(duì)應(yīng)的位就會(huì)翻轉(zhuǎn)成1,信號(hào)處理后,該位翻轉(zhuǎn)回0
也就是說(shuō),如果在信號(hào)處理期間,多次Ctrl+c,只是多次讓該信號(hào)對(duì)應(yīng)的位變成1,其效果和一次Ctrl+c的效果一樣
實(shí)踐內(nèi)容
signal函數(shù)
1 #include <stdio.h>
2 #include <signal.h>
3 void sig_catch(int signo){
4 printf("catch you : %d\n",signo);
5 return ;
6 }
7
8 int main(){
9 signal(SIGINT,sig_catch);
10 while(1);
11 return 0;
12 }
posted on 2022-10-30 15:28 20201321周慧琳 閱讀(13) 評(píng)論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)