Origin of zombie process

To understand how to avoid the zombie process, we first need to know where this problem comes from
The maximum value of Linux system process number is 32768


When the total number of PID reaches this value, the system will not be able to create a new process, which is a very serious problem


I once encountered a system bug, that is, when calling the external system, the external system did not return, the process would not be released and kept waiting, which eventually led to the bug of PID depletion
I don’t want to repeat the Linux Process tree here,


Under normal circumstances, when the process exits, the PID will be recycled by the parent process. The specific method is

  • When the child process ends, the system sends sigchild signal to its parent process
  • Blocking after the parent process calls the wait function
  • The parent process is awakened by the sigchild signal and then recovers the zombie child process

There is a special case where the parent process ends earlier than the child’s process. For example, the parent process is killed
In this case, the parent process of the child process will be directed to init (that is, process 1), so process 1 will be responsible for recycling
The init process in the early Linux system was very lightweight, called sysinit
However, in the modern Linux environment, the init process is generally a heavyweight process such as systemd or upstartd, which will do a lot of extra work.
(in fact, this issue has caused a lot of debate. Some developers believe that using a heavier init process will do more harm than good)
By constantly calling bash, you can get a standard process tree

We can see that the parent process of process 3099 is 3093, and its child processes include 3105, 3111, 3117 and 3123
Here, if you kill process 3099, you will find that the parent process of its direct child process 3105 has indeed become
/lib/systemd/systemd –user (PID 1634)
Although it is indeed systemd, what about the agreed process 1?
Process 1 is /sbin/init auto noprompt

Want to know why? After Ubuntu 18 (I’m currently Ubuntu 20),
/sbin/init is a soft link to / lib/system/systemd

On the above normal Linux system, even if we kill the parent process of 3105, it will not become a zombie. At this time, no zombie process can be found by using ps -ef | grep defunct


Go docker

After killing process 21, process 24 will be hosted to process 1 of docker


Docker process 1 is actually just an ordinary bash process
Send a Message