免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1056 | 回复: 0
打印 上一主题 下一主题

子进程对信号的继承 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-19 11:27 |只看该作者 |倒序浏览

                                                                                #include
#include
#include
void new_op(int,siginfo_t*,void*);
int main(int argc,char**argv)
{
    struct sigaction act;
    int sig;
    pid_t pid;        
   
    pid=getpid();
    sig=atoi(argv[1]);   
   
    sigemptyset(&act.sa_mask);
    act.sa_sigaction=new_op;
    act.sa_flags=SA_SIGINFO;
    if(sigaction(sig,&act,NULL)si_int);
}
输出:
child pid is 21309
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
信号处理函数中打印的进程号和子进程是一致的,子进程继承了父进程对信号的处理。
再来看看fork系统调用的说明:   
  
功能描述:
建立一个子进程。所建立的子进程PID 和 PPID不同于其父进程,同时资源使用被设置为0,文件锁和挂起的信号不被继承。
Linux内部,fork的执行使用copy-on-write页面,所以耗费的资源只是拷贝父进程页表,建立唯一子进程task结构体的时间和内存。
其中提到了挂起的信号不被继承,哪什么是挂起的信号呢?[color="#000000"]已经生成但还未被传递的信号被称为挂起的信号。

在进程的task_struct结构中有关于本进程中未处理信号的数据成员:
          struct sigpending pending:
struct sigpending{
        struct sigqueue *head, **tail;
        sigset_t signal;
};
其中head和tail是信号队列的指针,挂起的信号就是已经添加到信号队列里,但还没有处理的信号。
[color="#000000"]参考资料[color="#000000"]http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html
[color="#000000"]http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html
               
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72751/showart_1133793.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP