Linux--信号处理:在某个信号发生时屏蔽其他的信号

来源:互联网 发布:软件著作权 翻译 编辑:程序博客网 时间:2024/05/16 14:49

在下面代码中,在SIGINT信号处理过程中,屏蔽SIGQUIT信号的发生,信号SIGQUIT直到SIGINT的信号处理函数完毕后才能被处理

#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <signal.h>void sig_handle(int signo){int i = 5;printf("catch signal %d\n", (int)signo);while(i--){printf("wait another signal\n");sleep(1);}}int main(int argc, char *argv[]){struct sigaction newact, oldact;newact.sa_handler = sig_handle;sigemptyset(&newact.sa_mask);sigaddset(&newact.sa_mask, SIGQUIT);newact.sa_flags = 0;sigaction(SIGINT, &newact, &oldact);while(1){printf("main process\n");sleep(1);}return 0;}


0 0
原创粉丝点击