How to kill zombie process

前端 未结 6 1416
暗喜
暗喜 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:02

    Sometimes the parent ppid cannot be killed, hence kill the zombie pid

    kill -9 $(ps -A -ostat,pid | awk '/[zZ]/{ print $2 }')
    
    0 讨论(0)
  • 2020-12-02 04:08

    I tried:

    ps aux | grep -w Z   # returns the zombies pid
    ps o ppid {returned pid from previous command}   # returns the parent
    kill -1 {the parent id from previous command}
    

    this will work :)

    0 讨论(0)
  • 2020-12-02 04:14

    I tried

    kill -9 $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
    

    and it works for me.

    0 讨论(0)
  • 2020-12-02 04:19

    Found it at http://www.linuxquestions.org/questions/suse-novell-60/howto-kill-defunct-processes-574612/

    2) Here a great tip from another user (Thxs Bill Dandreta): Sometimes

    kill -9 <pid>
    

    will not kill a process. Run

    ps -xal
    

    the 4th field is the parent process, kill all of a zombie's parents and the zombie dies!

    Example

    4 0 18581 31706 17 0 2664 1236 wait S ? 0:00 sh -c /usr/bin/gcc -fomit-frame-pointer -O -mfpmat
    4 0 18582 18581 17 0 2064 828 wait S ? 0:00 /usr/i686-pc-linux-gnu/gcc-bin/3.3.6/gcc -fomit-fr
    4 0 18583 18582 21 0 6684 3100 - R ? 0:00 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/cc1 -quie
    

    18581, 18582, 18583 are zombies -

    kill -9 18581 18582 18583
    

    has no effect.

    kill -9 31706
    

    removes the zombies.

    0 讨论(0)
  • 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}')
    
    0 讨论(0)
  • 2020-12-02 04:29

    You can clean up a zombie process by killing its parent process with the following command:

    kill -HUP $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
    
    0 讨论(0)
提交回复
热议问题