How to Handle Zombie Processes in Ubuntu
Today, when I logged into the console, I found the following output:
There are 20 zombie processes
Console Outputzombie, my first thought was a Trojan (I just set up my new server, so where could a Trojan come from? And how could Ubuntu scan for a Trojan on its own, let alone 20 of them?).
After checking, it turns out it wasn't what I had imagined. The definition (from Jianshu) is as follows:
APEU2's definition of a zombie process: In UNIX system terminology, a process that has terminated but whose parent has not yet waited for it is called a zombie. When a parent thread does not use the wait method to get the termination status of its child thread, the child thread becomes a zombie after it terminates.
The dangers of zombie processes When a child thread ends, it sends a SIGCHLD signal to the parent thread. The parent thread enters the wait method to release related resources and close open files, etc. When the parent thread doesn't know that the child thread has ended and doesn't enter the wait method to release resources, a large number of zombie processes will consume a lot of system resources. On the other hand, the process ID of the child process is still occupied. When a large number of zombie processes occur, it may cause the system to be unable to create new processes.
Indeed, it's not something good.
So, we can use the following command to view all zombie processes:
ps aux | grep Z
Console Output
We can solve this using the following command:
ps -eo pid,ppid,stat,cmd | grep 'Z' # Find zombie processes and their parent processes
kill -HUP <PPID> # Send SIGHUP signal to the parent process, where <PPID> is the parent process ID
Alternatively, you can choose to terminate the parent process:
kill -9 <PPID> # Forcefully terminate the parent process