Is there any way to kill a zombie process without reboot?

142,238

Solution 1

I don't thing zombie process is much of a headache. A zombie process does not take up any resources. It is just that it has it's entry in the process table.

A Zombie process is not an orphan process, it does have a parent.

kill, skill pkill will not work since the process is already killed, just that it's entry has not been removed.

Zombie process can be killed by sending SIGCHLD signal to parent. I think the signal number of SIGCHLD is 17 or 18

If this also fails, then you might want to kill the parent itself.

From Wikipedia on SIGCHLD signal:

When a child process terminates before the parent has called wait, the kernel retains some information about the process to enable its parent to call wait later. Because the child is still consuming system resources but not executing it is known as a zombie process.


EDIT 1: The system resources consumed is mostly the process table entry. If anyone knows if it consumes more than that - memory or CPU cycle, then please add an explanation. AFAIK it hardly takes up any significant system resources.


EDIT 2: Quoting from Wikipedia

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the (now zombie) process to read its exit status.

So the entry is kept so that the parent process can know the exit status because the moment the child exits, the parent is probably not in a state or not ready to read it's exit status.


EDIT 3

Till date I never experienced a zombie process taking 100% of the CPU. Seeing this for the first time.

Try doing a killall utorrent.exe

I can see that there are two instances of utorrent.exe and one of them is zombie. Probably the second one (child). killall should kill the parent since the child(zombie) cannot be killed.


EDIT 4

Looks like the killall did not work since it was giving TERM signal instead of KILL.

Try out killall --signal=KILL utorrent.exe

If this does not work then try killing the process selectivly.

Get the list of utorrent.exe process PID

ps -e | grep -i utorrent

You should get two process like

xxxx ?        aa:bb:cc utorrent.exe defunct
yyyy ?        aa:bb:cc utorrent.exe

So the second one is the parent. Kill it using

kill -9 yyyy

EDIT 5

Please try finding the process's Parent Id by this bash command

cat /proc/{defunctpid}/status | grep -i ppid

in your case is

cat /proc/7298/status | grep -i ppid

If the output comes like

PPid: 1

Then sadly I think you are out of luck. Process Id 1 belongs to init without which your system cannot run

Solution 2

Using kill on the process itself is indeed ineffective, as the process is already dead; kill brings a live process to zombie state.

The parent process is responsible for picking up the exit code of the process; the process remains a zombie until this is done. The init process will pick up the exit code of any process and throw it away, so it is the "last-resort" parent that will clean up any zombie that is a direct descendant.

Killing the parent of the zombie process is usually effective because the zombie process then reverts to init as its parent as soon as the parent process is gone (i.e. killing the parent has turned that process into a zombie, and the grandparent has read the parent's exit code, so the parent is truly gone). A zombie can be parent to a zombie, so merely killing the parent is not sufficient, it also needs to be collected by another process itself.

Note that processes are never responsible for cleaning up their grandchildren -- they always revert to process 1 as parent (which is why daemon authors sometimes use a double fork() and terminate the process in the middle to fully disassociate the child process from the invoking shell)

The reason why killing wine probably isn't effective is because it wasn't really the parent of the zombie process; rather, the "utorrent.exe" that is a direct descendant of init is. This process however is still running normally, just neglecting its duties.

Solution 3

Much easier way than killall, -9, etc:

1)Use qBitorrent instead instead of the console uTorrent (I'm waiting for a GUI version as well and qBitorrent is essentially it).

2)If you are using 11.04 or above, hit alt+f2 (opens a special commands window), type xkill and your mouse is now an x. Click on the program you want to close (UI = process ID) and it will kill it for you.

Advanced tip: bind a keyboard shortcut for "xkill" like I have on my G15 macro keyboard.

Solution 4

In my case when wine hangs and i can not kill the Zombie child with a shotgun i would do:

wineserver -k then i would kill the "Son of the Process" killall -9 Oblivion.exe (For example)

For what i understand wineserver sends a signal to all its Zombie Childs that they are all going to die (Because of the shotgun you know) but sometimes a child thinks by itself and wants to take the world by storm. So i do the additional killall -9 or the kill -9 with the id of the process.

Share:
142,238

Related videos on Youtube

Pedram
Author by

Pedram

Computer Science M.Sc. student at University of Alberta, Canada. SOreadytohelp

Updated on September 17, 2022

Comments

  • Pedram
    Pedram over 1 year

    Is there any way to kill a zombie process without reboot? Here is how it happened:

    I want to download a 12GB file using torrent. After adding the .torrent file, transmission turned into a zombie process (I tried ktorrent too. Same behavior). Finally I could download the file using µTorrent but after closing the program, it turns into a zombie as well.

    I tried using kill, skill and pkill with different options and -9 signal but no success.

    After reading some solutions on web, I found out killing the parent can kill the zombie. But killing wine didn't help either.

    Is there another way?

    Edit:

    ps -o pid,ppid,stat,comm

    PID  PPID STAT COMMAND
    7121  2692 Ss   bash
    7317  7121 R+   ps
    

    pstree output:

    init─┬─GoogleTalkPlugi───4*[{GoogleTalkPlug}]
     ├─NetworkManager─┬─dhclient
     │                └─{NetworkManager}
     ├─acpid
     ├─amarok───19*[{amarok}]
     ├─apache2───5*[apache2]
     ├─atd
     ├─avahi-daemon───avahi-daemon
     ├─bonobo-activati───{bonobo-activat}
     ├─clock-applet
     ├─console-kit-dae───63*[{console-kit-da}]
     ├─cron
     ├─cupsd
     ├─2*[dbus-daemon]
     ├─2*[dbus-launch]
     ├─desktopcouch-se───desktopcouch-se
     ├─firefox───run-mozilla.sh───firefox-bin─┬─plugin-containe───8*[{plugin-contain}]
     │                                        └─14*[{firefox-bin}]
     ├─gconfd-2
     ├─gdm-binary─┬─gdm-simple-slav─┬─Xorg
     │            │                 ├─gdm-session-wor─┬─gnome-session─┬─bluetooth-apple
     │            │                 │                 │               ├─compiz───sh───gtk-window-deco
     │            │                 │                 │               ├─fusion-icon
     │            │                 │                 │               ├─gdu-notificatio
     │            │                 │                 │               ├─gnome-panel───{gnome-panel}
     │            │                 │                 │               ├─gnome-power-man
     │            │                 │                 │               ├─gpg-agent
     │            │                 │                 │               ├─gwibber-service
     │            │                 │                 │               ├─nautilus
     │            │                 │                 │               ├─nm-applet
     │            │                 │                 │               ├─polkit-gnome-au
     │            │                 │                 │               ├─2*[python]
     │            │                 │                 │               ├─qstardict───{qstardict}
     │            │                 │                 │               ├─ssh-agent
     │            │                 │                 │               ├─tracker-applet
     │            │                 │                 │               ├─trackerd
     │            │                 │                 │               ├─wakoopa─┬─wakoopa
     │            │                 │                 │               │         └─3*[{wakoopa}]
     │            │                 │                 │               └─{gnome-session}
     │            │                 │                 └─{gdm-session-wo}
     │            │                 └─{gdm-simple-sla}
     │            └─{gdm-binary}
     ├─6*[getty]
     ├─gnome-keyring-d───2*[{gnome-keyring-}]
     ├─gnome-screensav
     ├─gnome-settings-
     ├─gnome-system-mo
     ├─gnome-terminal─┬─bash───ssh
     │                ├─bash───pstree
     │                ├─gnome-pty-helpe
     │                └─{gnome-terminal}
     ├─gvfs-afc-volume───{gvfs-afc-volum}
     ├─gvfs-fuse-daemo───3*[{gvfs-fuse-daem}]
     ├─gvfs-gdu-volume
     ├─gvfsd
     ├─gvfsd-burn
     ├─gvfsd-computer
     ├─gvfsd-metadata
     ├─gvfsd-trash
     ├─hald─┬─hald-runner─┬─hald-addon-acpi
     │      │             ├─hald-addon-cpuf
     │      │             ├─hald-addon-inpu
     │      │             └─hald-addon-stor
     │      └─{hald}
     ├─indicator-apple
     ├─indicator-me-se
     ├─indicator-sessi
     ├─irqbalance
     ├─kded4
     ├─kdeinit4─┬─kio_http_cache_
     │          └─klauncher
     ├─kglobalaccel
     ├─modem-manager
     ├─multiload-apple
     ├─mysqld───10*[{mysqld}]
     ├─named───10*[{named}]
     ├─nmbd
     ├─notification-ar
     ├─notify-osd
     ├─polkitd
     ├─pulseaudio─┬─gconf-helper
     │            └─2*[{pulseaudio}]
     ├─rsyslogd───2*[{rsyslogd}]
     ├─rtkit-daemon───2*[{rtkit-daemon}]
     ├─smbd───smbd
     ├─snmpd
     ├─sshd
     ├─timidity
     ├─trashapplet
     ├─udevd───2*[udevd]
     ├─udisks-daemon─┬─udisks-daemon
     │               └─{udisks-daemon}
     ├─upowerd
     ├─upstart-udev-br
     ├─utorrent.exe───{utorrent.exe}
     ├─vnstatd
     ├─winbindd───2*[winbindd]
     ├─wnck-applet
     ├─wpa_supplicant
     └─xinetd
    

    System monitor and top show the zombie process is using resources:

    enter image description here

    enter image description here

    Edit 2: I think I found something. I tried to logout and saw this message:

    enter image description here

    Since other torrent clients have th same issue maybe it's something about file size.I'm using ubuntu 10.04 on ext4 partitions.Killing nautilus and sending SIGCHLD signal to it didn't work.

    • Mikel
      Mikel about 13 years
      Can you add the output of ps -o pid,ppid,stat,comm and pstree to your question?
    • user972876
      user972876 over 12 years
      I am having the same problem here and after googling it seems that this occurs when having encrypted your home folder during the installation and choosing to download torrents bigger than 4gb. I haven't been able to find any other way than a reboot to get rid of the zombie process eating 99% cpu. bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/431975 seems to deal with this but nothing much seems to have been done in order to solve this :(
    • Luis Alvarado
      Luis Alvarado over 12 years
      Also please read here: askubuntu.com/questions/48624/what-are-zombie-processes This will help solve many doubts.
  • maaartinus
    maaartinus about 13 years
    You wrote A zombie process does not take up any resources and cited the child is still consuming system resources ... it is known as a zombie process.
  • Manish Sinha
    Manish Sinha about 13 years
    Yeah. I updated the post to make it clear what I meant.
  • Pedram
    Pedram about 13 years
    The zombie process takes one of my CPU cores entirely.The usage of that core is on 100%.So it's not only the process table entry.I will add additional information to the question.
  • Manish Sinha
    Manish Sinha about 13 years
    This is the first time I am seeing a zombie process eating any resource. I also faced this problems, but never ever had this problem
  • Pedram
    Pedram about 13 years
    I tried killall already.Didn't work.
  • Pedram
    Pedram about 13 years
    Thanks for information.But what's the solution?
  • Pedram
    Pedram about 13 years
    It didn't work either.Besides transmission and ktorrent have the same problem and they have nothing to do with wine.
  • Simon Richter
    Simon Richter about 13 years
    Killing the real parent process, i.e. the one that ps waux lists in the PPID column for the zombie.
  • Pedram
    Pedram about 13 years
    As you can see in the pstree output "utorrent.exe" doesn't have any parent.
  • Simon Richter
    Simon Richter about 13 years
    There are two processes with that name, where one is the child of the other. I suspect the zombie is the child, which would make the parent "utorrent.exe" process responsible for cleanup; if you kill that process, then init will clean up the parent, after which the child is reattached to init and immediately cleaned up as well.
  • Luis Alvarado
    Luis Alvarado about 13 years
    I was mentioning the part about using utorrent with wine being wine the parent and utorrent the child. Anyway did you try to send a signal to the parent letting it know that its child is a zombie (Something no parent is ready for). For example: kill -s SIGCHLD ppid
  • Pedram
    Pedram about 13 years
    killall didn't work in that case.I started µTorrent now and it doesn't have any parent or child, but cannot be killed yet.pstree output is updated.
  • Manish Sinha
    Manish Sinha about 13 years
    Try killall --signal=KILL utorrent.exe
  • Pedram
    Pedram about 13 years
    Nothing happened.
  • Pedram
    Pedram about 13 years
    Unfortunately doesn't work either.
  • Pedram
    Pedram about 13 years
    My processor is core i7 860.
  • Manish Sinha
    Manish Sinha about 13 years
    Try the ps -e | grep -i utorrent part of Update 4
  • Pedram
    Pedram about 13 years
    Thanks for your great answer.But in answer of EDIT 4 I should say there is only 1 utorrent process: 17083 ? 00:20:45 utorrent.exe <defunct> which can't be killed using -9.
  • Pedram
    Pedram about 13 years
    Sorry for mistake.It's the same situation but kill all doesn't work.
  • Manish Sinha
    Manish Sinha about 13 years
    You might want to check the output of pstree now and see if utorrent.exe is shown only one or two times now (given that you can see only one utorrent process)
  • Pedram
    Pedram about 13 years
    Outout of pstree |grep utorrent is |-utorrent.exe---{utorrent.exe}.Updated pstree output is in the question.
  • Nathanael
    Nathanael about 13 years
    Always use pkill <process name> instead of killall <process name>. Killall kills everything on some versions of unix (ie. Solaris) so it's good to avoid it.
  • Manish Sinha
    Manish Sinha about 13 years
    I think that utorrent.exe process is now owned by init. The bigger question is when it is owned by init, why isn't init removing it?
  • Luis Alvarado
    Luis Alvarado about 13 years
    Interesting. Can you give me a step by step guide on how to create the problem your are facing. I have a friend who also has an i7 860 so i can test the problem there.
  • Pedram
    Pedram about 13 years
    Yeah.It's PPid: 1.Did you see the update in the question?
  • Pedram
    Pedram about 13 years
    I'm trying to download this torrent: kickasstorrents.com/… using utorrent.After a few minutes of download closing utorrent does not kill the process.
  • Pedram
    Pedram about 13 years
    Using Transmission can do the same too.But now I see it doesn't happen every time.Sometimes it turns into zombie and sometimes it doesn't.Also this time transmission doesn't use my processor (last time it did).But but utorrent use resources when it turns into zombie.
  • Manish Sinha
    Manish Sinha about 13 years
    Noticing it now. Too bad. Not sure how this situation has to be handled
  • Manish Sinha
    Manish Sinha about 13 years
    Too bad. No solution :(
  • Pedram
    Pedram about 13 years
    Thanks, but I'm using a normal hard disk.
  • Dolchio
    Dolchio over 11 years
    A zombie using CPU may be running background threads. Try using top -H to display threads instead of processes in top.
  • Eliah Kagan
    Eliah Kagan almost 11 years
    "When using an SSD however, the CPU is the bottleneck, and the application appears to have crashed (goes gray). If you leave it for a while, it will recover and all will be well." In that situation, the process is not a zombie. Zombie processes and processes in uninterruptible sleep are not the same thing. A zombie process truly is not running anymore, does not take up resources (except a single entry in the process table), and cannot ever come back to life.
  • Fish Monitor
    Fish Monitor over 10 years
    This post is of multiple issues...
  • devasia2112
    devasia2112 over 8 years
    That is the case -> cat /proc/<PID>/status | grep -i ppid --->> if the output comes like PPid: 1 ---->> "Then sadly I think you are out of luck. Process Id 1 belongs to init without which your system cannot run" No Solution. Only rebooting the box. ^_~
  • pietrovismara
    pietrovismara almost 8 years
    The major problem with defunct processes is that they keep using eventually used ports.
  • cgseller
    cgseller over 7 years
    Zombie process will also trick the system to leaving any kind of resource open, files, sockets, tcp ports, etc. This gets in the way of re-using those ports, unmounting volumes, delete files, etc. When a system runs out of resources (CPU, Memory, and mostly disk space) it can leave processes in this Zombie defunct state.