您的位置:首页 > 其它

★实验10-2 1. 编写程序测试sigaction()函数。 2. sa_flags 设置为以下标志时,程序的行为有何不同。 对比程序运行情况予以说明。 SA_SIGINFO SA_NOCLDST

2017-07-20 13:25 441 查看
★实验10-2
1.	编写程序测试sigaction()函数。
2.	sa_flags 设置为以下标志时,程序的行为有何不同。
对比程序运行情况予以说明。
SA_SIGINFO
SA_NOCLDSTOP
SA_NOCLDWAIT
SA_NODEFER
SA_RESETHAND
源代码:
#include <stdio.h>

#include <stdlib.h>

#include <signal.h>

#include <sys/types.h>

#include <unistd.h>
void show_handler(int sig)
{
printf("I got signal %d\n", sig);
int i;
for(i = 0; i < 5; i++) {
printf("i = %d\n", i);
sleep(1);
}
}

int main(void)
{
int i = 0;
struct sigaction act, oldact;
act.sa_handler = show_handler;
sigaddset(&act.sa_mask, SIGQUIT);
act.sa_flags = SA_RESETHAND | SA_NODEFER;
//act.sa_flags = 0;

sigaction(SIGINT, &act, &oldact);
while(1) {
sleep(1);
printf("sleeping %d\n", i);
i++;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐