linuxsignalsposixzombie-processwaitpid

What does signal(SIGCHLD, SIG_DFL); mean?


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 SIG_DFL then, will it work? How do I set SIGCHLD to SIG_DFL?

I want process to become zombie, so I can read the child status in parent after waitpid.


Solution

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

    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.

    2. 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.

    3. 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.)