My Linux process has 4 children. After some execution time all children adopted by the init process. How do we prevent this situation? (this is not the case with Zombie processes).
The process is written in C and the OS is Linux. My code calls waitpid! What might be the prob开发者_JAVA百科lem? In 99,99% we don't have this problem.
Last update: What if someone executes "kill -9 "? This terminates immediately the parent process and leaves the children orphan.
If your processes are being reparented by init
, that means that their parent process has died. When a process' parent dies, init
adopts it so that it can reap the zombie by wait()
ing on the child when it (that is, init
) receives SIGCHLD
.
If you do not want init
to become the parent of your children, you will have to ensure that your process lives until all of your children have died and been reaped by your program.
Wait for the children to exit before exiting yourself. See the wait(2)
man page for more details.
Check from main page for your waitpid API parameters, and make sure your parent process should not be over before all child processes are finished. Can you post your code here?
精彩评论