Introduction and harm of zombie processes and solutions

If you use Linux a lot, you should run into the term "Zombie Processes". So what is a zombie process? How did they come about? Are they harmful to the system? How do I kill these processes? These questions will be answered below.

What is a zombie process?

We all know how the process works. We start a program, start our task, and then wait for the task to end, we stop the process. When the process stops, the process is removed from the process table.

You can view the current process through System-Monitor.

Zombie process introduction and hazards and solutions

However, sometimes some programs remain in the process table even after they are executed.

Then, these processes that have completed the life cycle but remain in the process table, we call it "zombie process."

How did they come about?

When you run a program, it produces a parent process and many child processes. All of these child processes consume the memory and CPU resources that the kernel allocates to them.

After these sub-processes complete execution, they will send an Exit signal and die. This Exit signal needs to be read by the parent process. The parent process needs to subsequently call the wait command to read the exit status of the child process and remove the child process from the process table.

If the parent process correctly reads the Exit signal of the child process, the child process will be deleted from the process table.

However, if the parent process fails to read the Exit signal of the child process, the child process is dead in the execution, but it will not be deleted from the process table.

Is the zombie process harmful to the system?

will not. Since the zombie process doesn't do anything, it doesn't use any resources or affect other processes, so there is no harm in the existence of a zombie process. However, because the exit status in the process table and other process information are also stored in memory, there are too many zombie processes and sometimes problems.

You can imagine this:

“You are the boss of a construction company. You pay wages every day according to the workload of the workers. There is a worker who comes to the construction site every day, sits there, you don’t have to pay, he doesn’t do any work. He just does it every day. Come and sit there, nothing more!"

This worker is a living example of the zombie process. However, if you have a lot of zombie workers, your construction site will be very congested and it will make it difficult for normal workers to work.

So how do you find out the zombie process?

Open the terminal and enter the following command:

Ps aux | grepZ

The details of all zombie processes in the process table are listed.

How to kill the zombie process?

Normally we can use the SIGKILL signal to kill the process, but the zombie process is dead, you can't kill what is dead. So the command you need to enter should be

Kill -sSIGCHLD pid

Replace the pid here with the process id of the parent process, so that the parent process deletes all the child processes that completed and died.

You can think of it as:

"You found a body in the middle of the road, so you contacted the family of the deceased, and then they took the body off the road."

But many programs don't write so well, you can't delete these sub-zombies (otherwise you won't see these zombies at first). So the only way to ensure that child zombies are removed is to kill their parent process.


Patent Vape

Patent Vape,E-Cigarette Vape Pens,E-Cigarette Vaporizer Pen,Disposable Vape Puff Bar

Guangzhou Yunge Tianhong Electronic Technology Co., Ltd , https://www.e-cigarettesfactory.com