I’ve been trying desperately to kill a child process from the parent.
I’ve tried:
1. kill -15 pid
-
kill -shotgun pid
-
kill -9 pid
They all resolved in having the child process written as :
“defunct” (zombie) when ps -A in linux.
How do I kill the process and force it to be cleaned from the process table. I must have it cleaned because its lack of a record in the process table is how I verify in my code that the process is dead.
Thanks 🙂
If you want to collect the child process, you have to ask for its exit code using
waitpid. From the manpage:Usage is somewhat like:
If you want to return immediately, even if the child has not exited yet:
If you just want to collect all zombie children, without finding information about a specific child, you do:
You could do that in a loop until
waitpidreturns with a negative number (i.e. error) and errno indicates ECHILD.This, by the way, also allows you to actually find out what state the process has, read up on the manpage for further information.