What is Zombie Process and Kill Zombie Process in Linux

Channel: Linux
Abstract: What They Do & How to Use Them Detecting zombie processes You can find the zombie processes using Linux ps command. This command will list all process

In Linux OS, a zombie process or a defunct process is a finished (dead) process, but it has still occupied an entry in the process table. Normally, a child process that has completed its execution will send a SIGCHLD signal to the parent process which has created it. Then the parent process will send a wait system call through which it can read the child’s exit status. After receiving the wait system call, the child’s entry will get removed from the process table. In some cases, the parent may ignore the SIGCHLD signal which causes the finished process to still exist in the process table which makes it a zombie process. Sometimes, this is desirable for the parent process to ensure that it doesn’t allocate the same PID to another child.

When a process becomes dead, it will free up the memory and other resources allocated to it. So, a zombie process will not be using any resources at all, other than an entry in the process table. The problem may start only when a large number of zombie processes exist and system run out of PIDs. In this tutorial, we will see how a zombie process can be detected and terminated.

If the system generates large number of zombie processes, then it should be an application bug which needs to be checked for available patches to correct the problem.

What Is A VST Plugin? What They Do ...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

What Is A VST Plugin? What They Do & How to Use Them Detecting zombie processes

You can find the zombie processes using Linux ps command. This command will list all processes with a 「STAT」 column. If the process is a zombie process, the STAT column will have the character 「Z」. Using any of the following commands, you can find the zombie processes.

ps aux | awk '{ print $8 " " $2 }' | grep -w Z
ps –el | grep Z
Handling zombie process

As zombie processes don’t consume any resources, you can ignore it if the server runs smoothly. But in the case of server facing heavy load, large number of zombie processes may become an issue. So, in order to get rid of the zombie processes we can consider any of the following methods.

1) Sending SIGCHLD signal to the parent process of zombie

Upon receiving SIGCHLD command, the parent process must send a wait system call which will remove the zombie process. This can be accomplished by executing the following command.

kill -s SIGCHLD

PPID is the PID of the parent process which invoked the zombie child process. You can execute the following command to find the PPID of a zombie process.

ps aux -eo ppid | grep

If the parent process explicitly ignores the SIGCHLD signal, then you should consider killing the parent process (step 2).

2) Killing the parent process

If the zombie processes are not able to get removed, you should kill the parent process or restart the service to get rid of the zombies. When a parent gets killed, all child processes will become the child process of ‘init process (PID 1)’. Init process will wait for the children to die by sending a wait signal which in turn removes the zombie processes. The parent process can be killed using the ‘kill’ command:

kill -9

Please provide your thoughts and suggestions on this article. Thanks for reading.

Read Also:
  • How to Stop Process Using Kill Command in Linux

Ref From: linoxide
Channels:

Related articles