Zombie Process
Related topics:
What is a Zombie Process
A zombie (Z) 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. The act of reading that exit code is called "reaping" the child. Between the time a child exits and is reaped, it is called a zombie.
But long-lived zombies exist. What are they? They're the former children of an existing process that hasn't reaped them. The process may be hung. Or it may be poorly written and forgets to reap its children. Or maybe it's overloaded and hasn't gotten around to it. Or whatever. But for some reason, the parent process continues to exist (so they aren't orphans), and they haven't been waited on, so they live on as zombies in the process table.
Difference between Orphan process and Zombie process:
- In the Orphan process, the parent process has finished or terminated, though it remains running itself. * In the Orphan process, the parent process has finished or terminated, though it remains running itself.
- In a Unix-like OS, the special init system process immediately adopts any orphaned processes. This operation is called re-parenting and occurs automatically. Even though technically the process has the init process as its parent, it's still called an orphan process, since the process that originally created it no longer exists.
- In the Zombie process, the process has completed execution but still has an entry in the process table.
- Think "zombie": the process has "died" but has not yet been "reaped".
- Unlike normal processes, the kill command has no effect on a zombie process. When a process ends, all of the memory and resources associated with the process are de-allocated so they can be used by other processes. However, the process's entry in the process table remains.
How to view number of zombie processes? The 'top' command.
Main Points of Zombie Processes
Some of the important points related to zombie processes are as follows:
- All the memory and resources allocated to a process are deallocated when the process terminates using the exit() system call. But the process’s entry in the process table is still available. This process is now a zombie process.
- The exit status of the zombie process zombie process can be read by the parent process using the wait() system call. After that, the zombie process is removed from the system. Then the process ID and the process table entry of the zombie process can be reused.
- If the parent process does not use the wait() system call, the zombie process is left in the process table. This creates a resource leak.
- If the parent process is not running anymore, then the presence of a zombie process indicates an operating system bug. This may not be a serious problem if there are a few zombie processes but under heavier loads, this can create issues for the system such as running out of process table entries.
- The zombie processes can be removed from the system by sending the SIGCHLD signal to the parent, using the kill command. If the zombie process is still not eliminated from the process table by the parent process, then the parent process is terminated if that is acceptable.
The impact of Zombie Processes
Are Zombie processes bad or good? Do they impact system performance?
- Zombie processes don't use any system resources but they do retain their process ID in the process table. 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.
How to Clear or Kill Zombie Processes
- System reboot.
- Zombie processes can be killed by sending the SIGCHLD signal to the parent, using the kill command. This signal informs the parent process to clean up the zombie process using the wait() system call. This signal is sent with the kill command. It is demonstrated as follows:
kill -s SIGCHLD pid
(the pid is the process ID of the parent process.)
References:
https://www.tutorialspoint.com/what-is-zombie-process-in-linux
https://stackoverflow.com/questions/20688982/zombie-process-vs-orphan-process