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.
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
So your final target is to read return code in parent process after your child process exit? I don't see this has any matter with signal. Some example code is:
From your question history you seem to be tying yourself in knots over this. Here is the outline on how this works:
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.
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 andwait
will fail with ECHILD. (Linux kernels after 2.6.9 adhere to this behavior.)