/*************************************************************************
> 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信号,然后输出的值仍然是以前的值;

最新文章

  1. 使用excel计算指数平滑和移动平均
  2. Python 常用函数
  3. Await, and UI, and deadlocks! Oh my!
  4. 使用NHibernate(10) -- 补充(inverse &amp;&amp; cascade)
  5. cmd常用命令 和 sql server相关基础
  6. SQL数据插入:将截断字符串或二进制数据
  7. [SharePoint 2010]关于基于声明(Claims)的用户认证模式
  8. spring beans源码解读之--bean definiton解析器
  9. LeetCode_Scramble String
  10. PowerShell 批量导入/导出Active Directory
  11. LOOPS
  12. smarty模板做人员表信息删除,修改 里面的性别单选按钮民族下拉,另外登录进去可以显示姓名
  13. doT.js模板引擎及基础原理
  14. 大数据基础知识问答----hadoop篇
  15. UOJ#75. 【UR #6】智商锁 随机化算法 矩阵树定理
  16. (三)JavaScript 语法
  17. Windows平台下SVN安装配置及使用
  18. linux下关于PCL(point cloud library)库的安装,三行命令错误的问题
  19. 利用sql语句进行增删改查
  20. (9)How to take a picture of a black hole

热门文章

  1. C#百度api 根据经纬度获取地址
  2. 「NOI2015」荷马史诗 (k叉huffman树/k叉合并果子)
  3. harbor1.9仓库同步迁移
  4. axios并行请求
  5. .net SerialPort
  6. codeforces1213G Path Queries 并查集
  7. 数据结构实验之二叉树五:层序遍历 (SDUT 3344)
  8. 整理的 linux常用发行版 openstack images 下载地址
  9. Python流程控制和缩进
  10. 2015 ACM Arabella Collegiate Programming Contest