发出什么信号(SIGCHLD,SIG_DFL);意思是? [英] What does signal(SIGCHLD, SIG_DFL); mean?

查看:831
本文介绍了发出什么信号(SIGCHLD,SIG_DFL);意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在代码中处理SIGCHLD.终止后,我的过程仍然被立即删除.我希望它成为僵尸进程.如果我将SIGCHLD设置为SIGDFT,它将起作用吗?如何将SIGCHLD设置为SIGDFT?我希望进程成为僵尸,所以我可以在waitpid之后读取父级中的子级状态.

I am not handling SIGCHLD in my code. Still my process is removed immediately after termination. I want it to become zombie process. If I set SIGCHLD to SIGDFT then, will it work? How do I set SIGCHLD to SIGDFT? I want process to become zombie, so I can read the child status in parent after waitpid.

推荐答案

从您的问题历史记录来看,您似乎正在为此而烦恼.以下是有关其工作原理的概述:

From your question history you seem to be tying yourself in knots over this. Here is the outline on how this works:

  1. SIGCHLD的默认配置为忽略.换句话说,如果您什么也不做,则 signal 会被忽略,但是僵尸存在于进程表中.这就是为什么您可以在孩子死后随时在它上wait的原因.

  1. The default disposition of SIGCHLD is ignore. In other words, if you do nothing, the signal is ignored but the zombie exists in the process table. This why you can wait on it at any time after the child dies.

如果您设置了信号处理程序,则信号会被传递,您可以适当地收获它,但是(前)孩子在死亡和收获之间仍然是僵尸.

If you set up a signal handler then the signal is delivered and you can reap it as appropriate but the (former) child is still a zombie between the time it dies and the time you reap it.

如果您手动通过signal将SIGCHLD的处理方式设置为SIG_IGN,则其语义与第1项中的语义略有不同.当您手动设置此处理方式时,操作系统会立即删除进程表中的子进程死亡时,并创建僵尸.因此,不再需要任何状态信息,并且wait将因ECHILD而失败. (2.6.9之后的Linux内核遵循此行为.)

If you manually set SIGCHLD's disposition to SIG_IGN via signal then the semantics are a little different than they are in item 1. When you manually set this disposition the OS immediately removes the child from the process table when it dies and does not create a zombie. Consequently there is no longer any status information to reap and wait will fail with ECHILD. (Linux kernels after 2.6.9 adhere to this behavior.)

这篇关于发出什么信号(SIGCHLD,SIG_DFL);意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆