sigaction-sigqueue
来源:互联网 发布:备案域名交易平台top 编辑:程序博客网 时间:2024/06/15 05:33
#include<stdio.h>#include<stdlib.h>#include<signal.h>#include <unistd.h>/********************************************************************* PCB: block----------pending 0 1 1 0 sigprocmask sigpending if signal is blocked(sigprocmask),the bit is 1,we can read the bit to use sigpending*********************************************************************/#if 0struct sigaction { void (*sa_handler)(int); void (*sa_sigaction)(int, siginfo_t *, void *); sigset_t sa_mask; int sa_flags; void (*sa_restorer)(void);};#endif#if 0union sigval { int sival_int; void *sival_ptr; };#endifvoid handler(int num,siginfo_t *s_t,void *p){ int receive_data = 0; if(num == SIGINT) { receive_data = s_t->si_int; printf("receive sig num is %d,data is %d \n",num,receive_data); }else if(num == SIGRTMIN){ receive_data = s_t->si_int; printf("receive sig num is %d,data is %d\n",num,receive_data); }else if(num == SIGUSR1) { sigset_t set;//for set the bit of block sigemptyset(&set); sigaddset(&set,SIGINT); sigaddset(&set,SIGRTMIN); sigprocmask(SIG_UNBLOCK,&set,NULL); printf("unblock of sigint and signalrtmin......\n"); }}int main(){ sigset_t set;//for set the bit of block struct sigaction my_set; my_set.sa_sigaction = handler; my_set.sa_flags=SA_SIGINFO; sigaction(SIGINT,&my_set ,NULL); sigaction(SIGRTMIN,&my_set,NULL); sigaction(SIGUSR1,&my_set,NULL); sigemptyset(&set); sigaddset(&set,SIGINT); sigaddset(&set,SIGRTMIN); sigprocmask(SIG_BLOCK,&set,NULL); pid_t pid = fork(); if(pid == 0) { int i = 0; union sigval test; test.sival_int = 201; for(i = 0; i <3 ;i++) { printf("send sigint....\n"); sigqueue(getppid(),SIGINT,test); test.sival_int++; } test.sival_int = 300; for(i = 0; i <3 ;i++) { printf("send sigrtmin.....\n"); sigqueue(getppid(),SIGRTMIN,test); test.sival_int++; } kill(getppid(),SIGUSR1); }else if(pid > 0){ while(1) { sleep(1); } }}
send sigint....send sigint....send sigint....send sigrtmin.....send sigrtmin.....send sigrtmin.....receive sig num is 34,data is 300receive sig num is 34,data is 301receive sig num is 34,data is 302receive sig num is 2,data is 201 unblock of sigint and signalrtmin......
as:
1.可靠信号与不可靠信号同时发了3次,可靠信号全部抵达,不可靠信号抵达1次。
2.sigprocmask阻塞后,解除阻塞信号仍然会抵达。
3.sigqueue和sigaction可以传送数据。
4.block为1,pending就是0,表示未达状态。当block为unblock后,sending为0,信号可以抵达。
5.不解之处:SIGINT已经设置为unblock,但是ctrl+c,仍然无法终止进程。
阅读全文
0 0
- sigaction-sigqueue
- linux sigaction and sigqueue
- sigaction和sigqueue
- Linux c 信号—sigaction、sigqueue
- 信号发送(sigqueue)和接收(sigaction)
- 信号发送函数sigqueue和信号安装函数sigaction
- Linux信号控制-sigprocmask,sigsuspend,sigpending,sigaction,sigqueue
- 十八、Linux系统编程-信号(五)sigaction和sigqueue
- 信号发送函数sigqueue和信号安装函数sigaction
- 信号发送函数sigqueue和信号安装函数sigaction
- 信号发送函数sigqueue和信号安装函数sigaction
- 信号编程之sigaction函数和sigqueue函数
- linux信号捕捉和sigaction函数和sigqueue函数
- linux学习---信号(signal,sigaction,kill,sigqueue,sigprocmask,sigpending,sigsuspend)
- linux系统编程之信号(六):信号发送函数sigqueue和信号安装函数sigaction
- linux 信号的捕捉和发送函数的简单使用:sigaction()和sigqueue()
- linux系统编程之信号(六):信号发送函数sigqueue和信号安装函数sigaction
- 信号相关函数(signal,sigaction,sigprocmask, kill,sigqueue信号发送函数,睡眠函数,计时器函数)
- Kaldi HMM拓扑和状态转换模型
- VueJs 监听 window.resize 方法---窗口变化
- WAP_WSP的Well-known header
- 优雅的QSignleton (一) Singleton单例实现
- MySQL学习(二)【MySQL数据库对象与应用】
- sigaction-sigqueue
- 解决客户端 query did not return aunique result:2
- 树莓派硬件PWM输出程序
- 隐语义模型
- SOA中springmvc中restful服务的数据权限加密方式分享
- GridLayoutManager画分割块,同时不影响item内容的宽高
- C# 正则表达式 使用介绍
- 学习笔记TF060:图像语音结合,看图说话
- 在SSH框架中,使用Spring设置定时器Quartz来开启定时任务