Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why does linux produce zombie?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces why linux produces zombie related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain something after reading this linux why zombie article, let's take a look at it.

The reason why linux produces zombie (zombie process) is that after the parent process produces a child process, the child process exits before the parent process, but the parent process does not handle the exit signal sent by the child process, so the child process will be called a zombie process; at this time, the use of root identity can not kill kill the process, it can be solved by killing the parent process of the child process.

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the reason why linux produces zombie?

Cause:

Zombie process, the English name zombie process, as the name implies, is a dead process. So what is the origin of the zombie process?

The reason for the zombie process is that after the parent process produces the child process, the child process exits before the parent process, but the parent process does not handle the exit signal sent by the child process for various reasons, so the child process will become a zombie process.

This is the so-called zombie (zombie process) means that in the fork () / execve () process, assuming that the parent process still exists when the child process ends, and the parent process fork () does not install the SIGCHLD signal handling function to call waitpid () to wait for the child process to finish, and does not explicitly ignore the signal, then the child process becomes a zombie process and cannot end normally, even the root identity kill-9 cannot kill the zombie process at this time. The remedy is to kill the parent process of the zombie process (the parent process of the zombie process must exist), the zombie process becomes an "orphan process", and the init,init will always be responsible for cleaning up the zombie process.

A zombie process means that the parent process has exited, and the zombie process becomes a zombie process if no process accepts it after dead.

Solution:

(1) the parent process waits for the child process to end through functions such as wait and waitpid, which will cause the parent process to hang.

When the wait () or waitpid () system call is executed, the child process returns its data in the process table to the parent process immediately after termination, and the entry point is deleted immediately. In this case, no defunct process is generated.

(2) if the parent process is busy, you can use the signal function to install handler for SIGCHLD. After the child process ends, the parent process receives the signal and can call wait collection in handler.

(3) if the parent process does not care about when the key content child process ends, you can use signal (SIGCLD, SIG_IGN) or signal (SIGCHLD, SIG_IGN) to notify the kernel that you are not interested in the end of the child process, then the kernel will recover after the child process ends and no longer send a signal to the parent process.

(4) fork twice, the parent process fork a child process, and then continue to work, the child process fork a grandchild process and then quit, then the grandchild process is taken over by init, and when the grandchild process ends, the init will be reclaimed. However, the recycling of the child process has to be done by yourself.

This is the end of the article on "Why linux produces zombie". Thank you for reading! I believe you all have a certain understanding of the knowledge of "why linux produces zombie". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report