Thursday, November 1, 2018

What is Zombie Process in Linux?

In this post you will learn about Zombie Process on Linux.A zombie process is a process whose execution is completed but it still has an entry in the process table. Zombie processes usually occur for child processes, as the parent process still needs to read its child’s exit status. Once this is done using the wait system call, the zombie process is eliminated from the process table.

How zombie gets created:

Whenever we run a program it creates a parent process and a lot of child processes. All of these child processes use resources such as memory and CPU allocated to them by the kernel.

Once these child processes have finished executing they send an Exit call and die. This Exit call has to be read by the parent process which later calls the wait command to read the exit_status of the child process so that the child process can be removed from the processes table.

If the Parent reads the Exit call correctly sent by the Child Process, the process is removed from the processes table.

But, if the parent fails to read the exit call from the child process, the child process which has already finished its execution and is now dead will not be removed from the processes table.


How to find Zombie Processes?

Open a terminal and type the following command -

ps aux | grep Z

You will now get details of all zombie processes in the processes table.

How to kill Zombie processes?

Normally we kill processes with the SIGKILL command but zombie processes are already dead. You Cannot kill something that is already dead. So what you do is you type this command -

kill -s SIGCHLD pid

​Replace the pid with the id of the parent process so that the parent process will remove all the child processes that are dead and completed.

Harms of Zombie Processes

Zombie processes don't use any system resources but they do retain their process ID. If there are a lot of zombie processes, then all the available process ID’s are monopolized by them. This prevents other processes from running as there are no process ID’s available.

The presence of zombie processes also indicates an operating system bug if their parent processes are not running anymore. This is not a serious problem if there are a few zombie processes but under heavier loads, this can create issues for the system.

No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...