How to kill zombie process

前端 未结 6 1433
暗喜
暗喜 2020-12-02 03:33

I launched my program in the foreground (a daemon program), and then I killed it with kill -9, but I get a zombie remaining and I m not able to kill it with

6条回答
  •  盖世英雄少女心
    2020-12-02 04:28

    A zombie is already dead, so you cannot kill it. To clean up a zombie, it must be waited on by its parent, so killing the parent should work to eliminate the zombie. (After the parent dies, the zombie will be inherited by pid 1, which will wait on it and clear its entry in the process table.) If your daemon is spawning children that become zombies, you have a bug. Your daemon should notice when its children die and wait on them to determine their exit status.

    An example of how you might send a signal to every process that is the parent of a zombie (note that this is extremely crude and might kill processes that you do not intend. I do not recommend using this sort of sledge hammer):

    # Don't do this.  Incredibly risky sledge hammer!
    kill $(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}')
    

提交回复
热议问题