Linux Bulk Deletion process and view process detailed

Source: Internet
Author: User
Tags tomcat

1. After typing 1-2 characters on the LINUX command platform, pressing the TAB key automatically complements the rest of the section (if you want to have this thing, for example, if you have Tomcat installed, enter Tomcat to press TAB).

2. The PS command is used to view the currently running process.
grep is a search
For example: Ps-ef | grep java
To view the process information in all processes CMD is Java
Ps-aux | grep java
-aux Show All States
Ps

3. Kill command to terminate process

Example: kill-9 [PID]
-9 to force the process to stop immediately
Usually use PS to view process PID, terminate process with kill command
The content of these two pieces on the Internet


4. Bulk Deletion process


Introduces two methods. The process to kill has a common string.

The code is as follows Copy Code
[Plain]
Kill-9 ' Ps-ef |grep Xxx|awk ' {print $} '


The symbol behind the kill-9 is the one above the TAB key.

As above is kill-9 ' list process, find the row containing xxx, output PID column '

Kill, PS, and grep are common commands.

The function of awk is to output a column, {print $} is the output of the second column, as above is the PID column. Here's a tutorial on awk

The code is as follows Copy Code
[Plain]
Ps-ef | grep XXX | Grep-v Root | awk ' {print $} ' | Xargs kill-9


Grep-v the function of this parameter is to exclude a character. So this excludes the commands that root executes.

And then use awk to find the PID column.

The final Xargs is the program that gets the parameters from the standard output and executes the command, which takes the output from the previous command as a parameter to execute the next command.


5. Clean up the zombie process

Cases

Today, while maintaining the server, 5 Nova-novncproxy zombie processes were found.

?
26327?        s      0:05  _/usr/bin/python/ Usr/bin/nova-novncproxy--config-file=/etc/nova/nova.conf
 4765?         z      0:00      _ [nova-novncproxy] <defunct>
 4766?        z      0:00       _ [Nova-novncproxy] <defunct>
 4767?        z & nbsp;    0:00      _ [nova-novncproxy] <defunct>
 4768?         z      0:00      _ [ Nova-novncproxy] <defunct>
 4769?        z       0:00      _ [nova-novncproxy] <defunct>


It's hard to kill a zombie in general, but you can kill a zombie dad. After the parent process dies, the zombie process becomes an "orphan process", and the adoptive 1th process Init,init is always responsible for cleaning up the zombie process. All the zombie processes it produces are also disappearing.

The code is as follows Copy Code

PS-E-O Ppid,stat | grep Z | Cut-d ""-f2 | Xargs kill-9

Or

Kill-hup ' Ps-a-ostat,ppid | Grep-e ' ^[zz] ' | awk ' {print $} '

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

I will nova-novncproxy stop and then start, the zombie process disappears, problem solved.

In addition, when the subprocess dies, the SIGCHLD signal is sent to the parent process, and the parent process receives the signal and executes the waitpid () function to bury the child process. is based on the principle that even if the parent process does not call wait, the kernel sends the SIGCHLD message to it, while the default processing for it is ignored, and if you want to respond to this message, you can set up a handler function.

6. How do you avoid zombie processes?


Processing of SIGCHLD signals is not necessary. However, for some processes, especially server processes, it is often necessary to generate a subprocess processing request when the request arrives. If the parent process does not wait for the child process to end, the child process becomes a zombie process (zombie) that consumes system resources. If the parent process waits for the child process to end, it will increase the burden on the parent process and affect the concurrency performance of the server process. The operation of the SIGCHLD signal can be simply set to Sig_ign under Linux.
Signal (sigchld,sig_ign);
In this way, the kernel does not produce a zombie process at the end of the subprocess. This is different from the BSD4, BSD4 must explicitly wait for the child process to end to release the zombie process

Or

With two times fork (), and the immediate child process to exit directly, the grandson process becomes an orphan process, thus the INIT process will be responsible for the removal of this orphan process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.