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

How to check and kill zombie process in Linux system

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to detect and kill zombies in the Linux system. I think it is very practical, so I share it with you. I hope you can get something after reading this article.

1. How to view the zombie process?

How to view zombie processes on a linux system, and how to count how many zombie processes are there?

The code is as follows:

# ps-ef | grep defunct

Or find a process with a status of Z, which stands for zombie process, which means zombie process.

In addition, there is a column S when you use the top command to view it. If the status is Z, it is a zombie process.

The code is as follows:

Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie

Zombie progress is also counted in the top command. Or use the following command:

The code is as follows:

Ps-ef | grep defunct | grep-v grep | wc-l

2. How to kill the zombie process?

General zombie processes are difficult to kill directly, but you can kill zombie dads. After the death of the parent process, the zombie process becomes an "orphan process", and the successor to process 1 init,init will always be responsible for cleaning up the zombie process. All zombie processes it produces also disappear.

The code is as follows:

Ps-e-o ppid,stat | grep Z | cut-d ""-f2 | xargs kill-9

Or

The code is as follows:

Kill-HUP `ps-A-ostat,ppid | grep-e'^ [Zz]'| awk'{print $2}'`

Of course, you can write a better shell script yourself, welcome to share it with you.

After another child process dies, it sends a SIGCHLD signal to the parent process. After receiving this signal, the parent process executes the waitpid () function to collect the corpse for the child process. It is based on the principle that the kernel sends a SIGCHLD message to the parent process even if it does not call wait, and at this point, although the default processing for it is ignored, you can set a handler if you want to respond to this message.

3. How to avoid zombie process?

It is not necessary to process SIGCHLD signals. However, for some processes, especially server processes, they often generate child processes to process requests when the request arrives. If the parent process does not wait for the child process to be bundled, the child process will become a zombie process (zombie) and consume system resources. If the parent process waits for the child process to finish, it will increase the burden on the parent process and affect the concurrency performance of the server process. Under Linux, the operation of SIGCHLD signal can be simply set to SIG_IGN.

Signal (SIGCHLD,SIG_IGN)

The above is how to detect and kill zombies in the Linux system. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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