Science and technology

How to kill a zombie course of on Linux

Happy Halloween Open SOURCE-rers!

Here’s a story as outdated as epoch time. Since there was C and Unix, and (in a while) Linux, we have had zombies. Specifically, there are processes that get marked as a zombie course of. Misunderstood by some, ignored by others, and proof against the efforts of so many people making an attempt to kill these processes with out a lot success. Why is that?

What is a course of in Linux?

It all begins when a program in Linux will get executed, and when it does, its working occasion known as a course of. You can see all processes in your Linux atmosphere with the ps command.

$ ps -ax
        PID TTY         STAT   TIME COMMAND
        1 ?     Ss      0:01 /usr/lib/systemd/systemd rhgb --switched-root --sys
        2 ?     S       0:00 [kthreadd]
        3 ?     I<      0:00 [rcu_gp]
        4 ?     I<      0:00 [rcu_par_gp]

Sometimes a course of begins one other course of, making the primary course of the father or mother of the second. The pstree command is a superb software that permits you to see the processes’ “genealogy” in your system.

$ pstree -psn
systemd(1)─┬─systemd-journal(952)
        ├─systemd-udevd(963)
        ├─systemd-oomd(1137)
        ├─systemd-resolve(1138)
        ├─systemd-userdbd(1139)─┬─systemd-userwor(12707)
        │                     ├─systemd-userwor(12714)
        │                     └─systemd-userwor(12715)
        ├─auditd(1140)───{auditd}(1141)
        ├─dbus-broker-lau(1164)───dbus-broker(1165)
        ├─avahi-daemon(1166)───avahi-daemon(1196)
        ├─bluetoothd(1167)

Every course of will get assigned a quantity within the system. Process ID #1 will get assigned to the very first course of executed throughout the boot course of, and each subsequent course of after PID 1 is a descendant of it. The PID 1 course of is the init, which on most newer variations of Linux is only a symbolic hyperlink to the systemd program.

Ending a course of with the kill command

You can terminate processes in a Linux system with the kill commandDespite the title, the kill command and a set of others similar to pkill and killall obtained written/designed to ship SIGNALS to a number of processes. When not specified, the default SIGNAL it sends is the SIGTERM sign to terminate the method.

When a father or mother course of dies or will get killed, and its little one course of does not observe its father or mother’s demise, we name that course of an orphan course of.

How to kill a zombie course of

Zombie processes, then again, can’t be killed! Why would possibly you ask? Well, as a result of they’re already useless!

Every little one course of, when terminated, turns into a zombie course of after which eliminated by the father or mother. When the method exits its existence and releases the assets it had used, its title continues to be on the OS course of desk. It is then the father or mother’s course of job to take away its title from the method desk. When that fails, now we have the zombie course of, which is not actually a course of anymore, however simply an entry on the method desk of the OS.

This is why making an attempt to do a kill command even with the -9 (SIGKILL) possibility on a defunct (zombie) course of does not work, as a result of there’s nothing to kill.

So, to kill a zombie course of, as in to take away its title from the method listing (the method desk), you must kill its father or mother. For occasion, if PID 5878 is a zombie course of, and its father or mother is PID 4809, then to kill the zombie (5878) you finish the father or mother (4809):

$ sudo kill -9 4809  #4809 is the father or mother, not the zombie

My remaining phrase of warning about zombies. Be very cautious when killing father or mother processes. If the father or mother of a course of is PID 1 and also you kill that, you may reboot your self!

And that will probably be a fair scarier story to inform!

Most Popular

To Top