#include <signal.h>
#include <unistd.h>
#include <stdio.h>
int main() {
sigset_t set;
int count=10;
sigemptyset(&set) ; //清空所有信號集
sigaddset(&set, SIGINT) ; //加入要屏蔽的信號
sigprocmask(SIG_BLOCK, &set, NULL) ;//設定阻塞信號
while(count){
printf("don’t disturb me (%d)\n", count--) ;
sleep(1);
}
sigprocmask(SIG_UNBLOCK, &set, NULL); //解除阻塞
sleep(10) ;
printf("you did not disturb me ! \n") ;
return 0;
}
shell上執行結果如下,不明白為什么在點擊Ctrl C 發送信號后,最后一句話為啥不出現了? :
uj5u.com熱心網友回復:
SIGSTOP/SIGKILL這兩個信號無法阻塞和屏蔽,應該是Ctrl+C行程直接退出了,所以不會列印轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/69383.html
標籤:系統維護與使用區
