linux 非可靠信号(31之前的信号)
2014-10-29 10:22
246 查看
1 当程序正在执行一个信号函数时,在函数执行期间,再次触发多个同样的信号,系统会保留一个
2 当程序正在执行一个信号函数时,在函数执行期间,再次触发一个不一样的信号,系统会暂停当前函数执行,跳转到新的信号
对应的函数去执行,执行完成后,才回到跳回之前所执行的函数中继续执行.
可以测试下面的程序
发送信号:
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
接受:
[d5000@localhost testcode]$ ./sigaction
process ID is 6624,time is 1414548809
0 Enter SignHandlerNew,signo:2. time=1414548819
1 Enter SignHandlerNew,signo:3. time=1414548833
1 Leave SignHandlerNew,signo:3 time=1414548863
2 Enter SignHandlerNew,signo:3. time=1414548863
2 Leave SignHandlerNew,signo:3 time=1414548893
0 Leave SignHandlerNew,signo:2 time=1414548893
3 Enter SignHandlerNew,signo:2. time=1414548893
3 Leave SignHandlerNew,signo:2 time=1414548923
process is over,time is 1414548923
可以看到2,3信号各接受2个,也就是各自等待一个!
2 当程序正在执行一个信号函数时,在函数执行期间,再次触发一个不一样的信号,系统会暂停当前函数执行,跳转到新的信号
对应的函数去执行,执行完成后,才回到跳回之前所执行的函数中继续执行.
可以测试下面的程序
#include <stdio.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <sys/time.h> int g_iSeq=0; void SignHandlerNew(int iSignNo,siginfo_t *pInfo,void *pReserved) { struct timeval tv; gettimeofday( &tv, NULL ); int iSeq=g_iSeq++; printf("%d Enter SignHandlerNew,signo:%d. time=%ld\n",iSeq,iSignNo,tv.tv_sec); sleep(10); /*睡眠3秒钟*/ gettimeofday( &tv, NULL ); printf("%d Leave SignHandlerNew,signo:%d time=%ld\n",iSeq,iSignNo,tv.tv_sec); } int main(void) { timeval tv; gettimeofday( &tv, NULL ); printf("process ID is %d,time is %ld\n",getpid(),tv.tv_sec); char szBuf[20]; /*输入缓冲区,长度为20*/ int iRet; struct sigaction act; /*包含信号处理动作的结构体*/ act.sa_sigaction=SignHandlerNew; /*指定信号处理函数*/ act.sa_flags=SA_SIGINFO; /*表明信号处理函数由sa_sigaction指定*/ sigemptyset(&act.sa_mask); /*信号集处理函数(稍后进行介绍),将act.sa_mask所指向的信号集清空,*/ /*即不包含任何信号*/ sigaction(SIGINT,&act,NULL); /* 注册SIGINT信号*/ sigaction(SIGQUIT,&act,NULL); /* 注册SIGQUIT信号*/ sleep(150); gettimeofday( &tv, NULL ); printf("process is over,time is %ld\n",tv.tv_sec); return 0; }
发送信号:
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGQUIT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
[d5000@localhost testcode]$ kill -SIGINT 6624
接受:
[d5000@localhost testcode]$ ./sigaction
process ID is 6624,time is 1414548809
0 Enter SignHandlerNew,signo:2. time=1414548819
1 Enter SignHandlerNew,signo:3. time=1414548833
1 Leave SignHandlerNew,signo:3 time=1414548863
2 Enter SignHandlerNew,signo:3. time=1414548863
2 Leave SignHandlerNew,signo:3 time=1414548893
0 Leave SignHandlerNew,signo:2 time=1414548893
3 Enter SignHandlerNew,signo:2. time=1414548893
3 Leave SignHandlerNew,signo:2 time=1414548923
process is over,time is 1414548923
可以看到2,3信号各接受2个,也就是各自等待一个!
相关文章推荐
- Linux中可靠信号与不可靠信号
- linux下信号编程简介——不可靠的信号
- linux下信号编程简介——不可靠的信号
- Linux 信号详解六(可靠信号与不可靠信号)
- linux下信号编程简介——不可靠的信号
- 十五、Linux系统编程-信号(二)信号分类、可靠信号与不可靠信号、信号发送 pause
- Linux信号实践(4) --可靠信号
- Linux信号实践(4) --可靠信号
- Linux可靠信号和不可靠信号
- Linux信号实践(4) --可靠信号
- Linux信号实践(4) --可靠信号
- Linux信号实践(4) --可靠信号
- linux可靠信号和非可靠信号测试样例
- Linux可靠信号和不可靠信号
- Linux可靠/不可靠信号编程实践
- Linux信号—可靠信号与不可靠信号实践
- Linux信号实践(4) --可靠信号
- Linux可靠信号和不可靠信号
- 七大步骤建立可靠的Linux操作系统
- Linux环境进程间通信系列(二):信号