#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
//信号处理函数
void handle1(int signo)
{
printf("捕捉到信号SIGINT\n");
}
//注册信号
void reg_signal()
{
signal(SIGINT, handle1);
}
int main()
{
//注册信号
reg_signal();
//信号集
sigset_t set, old_set;
//信号集操作函数
sigemptyset(&set);
sigemptyset(&old_set);
sigaddset(&set, SIGINT);
//把信号集添加到信号阻塞集
if(-1 == sigprocmask(SIG_BLOCK, &set, &old_set))
{
perror("sigprocmask");
exit(1);
}
printf("信号SIGINT阻塞成功!\n");
while(1);
return 0;
}