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 problem? 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,initadopts it so that it can reap the zombie bywait()ing on the child when it (that is,init) receivesSIGCHLD.If you do not want
initto 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.