- 论坛徽章:
- 0
|
//sigaction中的sa_mask域为一个阻塞信号集,表示当它执行信号处理例程时,
//会阻塞该信号集里的信号的递送,注意当前信号也会加入到这个阻塞的信号集里,
//最后,进程从处理函数中返回时,阻塞信号集会恢复到执行前的状态。
//在处理函数执行过程中(3~10秒),用 ^C发出一个中断信号。
#include
#include
void sig_alrm(int signo)
{
printf("in the alrm handler\n");
sleep(10);
printf("end of the alrm handler\n");
}
void sig_int(int signo)
{
printf("in the interrupt handler\n");
}
int main(void)
{
struct sigaction nact, oact;
nact.sa_handler = sig_alrm;
sigemptyset(&nact.sa_mask);
sigaddset(&nact.sa_mask, SIGINT);
nact.sa_flags = 0;
sigaction(SIGALRM, &nact, &oact);
//在信号处理函数执行时发生的中断信号由于被屏蔽而不能及时被递送,
//而会在处理函数返回后屏蔽信号恢复到原来值时才会被(延迟)递送。
signal(SIGINT, sig_int);
alarm(3);
sleep(5);
return 0;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/11445/showart_119022.html |
|