linux中高级信号函数sigaction和sigqueue实例
/*************************************************************************
> File Name: sigquque.c
> Author:
> Mail:
> Created Time: 2015年11月21日 星期六 14时33分25秒
************************************************************************/ #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h> //用新的回到函数接受数据。。。。
void myHandle_forsigaction(int signum, siginfo_t *s_t, void *p)
{
printf("parent recv a sig=%d data=%d data=%d\n", signum, s_t->si_value.sival_int, s_t->si_int);
} int main(int argc, char *argv[])
{
pid_t pid;
int ret = 0; struct sigaction act;
act.sa_sigaction = myHandle_forsigaction;
sigemptyset(&act.sa_mask); //如果父进程的回调函数, 准备接受额外数据
act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &act, NULL) < 0)
perror("sigaction error\n"); pid = fork(); if (pid == -1)
{
printf("fork err...\n");
return 0;
} if (pid == 0)
{
int i = 0; /*
union sigval {
int sival_int;
void *sival_ptr;
}; */ union sigval mysigval;
//mysigval.sival_ptr = (void *)&t;
mysigval.sival_int = 222; //kill(getppid(), SIGINT);
//带额外数据
for (i=0; i<10; i++)
{
ret = sigqueue(getppid(), SIGINT, mysigval);
if (ret != 0)
{
printf("sigqueue .....\n");
exit(0);
}
else
{
printf("child send the SIGINT signal by the funtion sigqueue...%d\n", i+1);
sleep(1);
}
}
exit(10);
}
else if (pid > 0)
{
int status;
int time = 20;
while(time){
time = sleep(time);
}
wait(&status);
if(WIFEXITED(status)){
printf("the child exit code is %d\n", WEXITSTATUS(status));
}
} exit(0);
}
最后四次是按下Ctrl+c给父进程发送SIGINT信号,然后输出的值仍然是以前的值;
linux中高级信号函数sigaction和sigqueue实例的更多相关文章
- linux中信号的API详解实例
/************************************************************************* > File Name: signal.c ...
- linux系统编程之信号(六):信号发送函数sigqueue和信号安装函数sigaction
一,sigaction() #include <signal.h> int sigaction(int signum,const struct sigaction *act,struct ...
- linux系统编程之信号:信号发送函数sigqueue和信号安装函数sigaction
信号发送函数sigqueue和信号安装函数sigaction sigaction函数用于改变进程接收到特定信号后的行为. sigqueue()是比较新的发送信号系统调用,主要是针对实时信号提出的(当然 ...
- Linux 改进捕捉信号机制(sigaction,sigqueue)
sigaction函数 sigaction函数的功能是用于改变进程接收到特定信号后的行为. int sigaction(int signum, const struct sigaction *act, ...
- Linux进程间通信—信号
三.信号(Signal) 信号是Unix系统中使用的最古老的进程间通信的方法之一.操作系统通过信号来通知某一进程发生了某一种预定好的事件:接收到信号的进程可以选择不同的方式处理该信号,一是可以采用默认 ...
- linux下的struct sigaction
工作中使用案例: struct sigaction act; act.sa_sigaction = handleSignal; act.sa_flags = SA_SIGINFO; sigemptys ...
- Linux 对信号的总结
Linux信号_总结 对信号本质的理解: 类似于中断,区别在于中断是由硬件产生的,而信号是由软件实现的. 信号的来源: 触发硬件(触发键盘,或是硬件故障):软件信号函数kill .alarm.seti ...
- 信号 signal sigaction补充
目前linux中的signal()是通过sigation()函数实现的. 由signal()安装的实时信号支持排队,同样不会丢失. 先看signal 和 sigaction 的区别: 关键是 stru ...
- Linux&C ——信号以及信号处理
linux信号的简单介绍 信号的捕捉和处理 信号处理函数的返回 信号的发送 信号的屏蔽 一:linux信号的简单介绍. 信号提供给我们一种异步处理事件的方法,由于进程之间彼此的地址空间是独立的,所以进 ...
随机推荐
- 2019HDU多校Minimal Power of Prime——分段讨论&&思维
题目 将 $n$($1 < n \leq 10^{18}$)质因数分解,求质因数幂的最小值. 分析 直接质因数分解,不太行. 可以这样想,对小区间质因数分解,n变小了,再枚举答案. 打印1-10 ...
- AS400上的binary数据显示不出
1.用DbVisualizer查询,结果免费的版本不支持 DSPFFD查看该table,column的Coded Character Set Identifier(CCSID)是65535,普通的是3 ...
- NVMe - NB的特性
翻译一下,纯粹是为了记住这些特性: NVMe provides the following benefits: ● Ultra-low latency 非常低的延迟 ● Very high throu ...
- getFieldDecorator用法(二)——封装表单模块
后台管理系统经常用到表单查询,因此做了个封装 myorder.js import React from 'react'; import { Card, Button, Table, Form, Sel ...
- struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []
使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...
- selenium安装与更新
1.通过pip show selenium 查看是否已经安装过selenium,如果已经安装selenium会显示安装的selenium的版本信息. 如果在使用pip 查看命令报Unknown or ...
- 游览器中javascript的执行过程
在讲这个问题之前,先来补充几个知识点,如果对此已经比较了解可以直接跳过 大多数游览器的组件构成如图 在最底层的三个组件分别是网络,UI后端和js解释器.作用如下: (1)网络- 用来完成网络调用,例如 ...
- ajax与HTML5 history API实现无刷新跳转
一.ajax载入与浏览器历史的前进与后退 ajax可以实现页面的无刷新操作,但是无法前进与后退,淡出使用Ajax不利于SEO.如今,HTML5让事情变得简单.当执行ajax操作时,往浏览器histor ...
- 响应式css样式
<div class="a"> 123 </div> @media(orientation:portrait) and (max-width:600px){ ...
- 美国top200药品2
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&u ...