[Linux] commands for using awk to batch kill processes

Source: Internet
Author: User

The use of AWK commands is a good choice when it comes to killing a certain type of process, and how to kill them in bulk.


Ps-ef| grep aaa| Grep|awk   '{print ' kill-9      ' $ |sh '

1. ps-ef| grep aaa| grep-v grep

This is a familiar command, and here is no longer a process that contains the AAA keyword from the process name of the process running on the current system.

2. The following section is the awk command, the format of the General awk command is: awk ' pattern {action} '

Print is printing, and kill-9 is the command that forces the process to stop, which is what is shown on the second column of the results that preceded the PS-EF command.

Here's a simple example:

#ps-ef|grep boco|grep-v grep
Root 9884 9883 0 17:10:01? 0:00 Sendmail-oem-oi-froot Boco
Root 9883 9880 0 17:10:01? 0:00/usr/bin/mail Boco
Boco 11112 1 0 Dec 24? 0:00./boco_appmaster-d/home/boco/agent
Boco 11126 11125 24 Dec? 52:59./boco_hostagent-i socket-l
Boco 11125 11112 Panax 24? 43:25./boco_appmaster-d/home/boco/agent
Boco 9811 11113 0 17:09:31? 0:00 Sleep 60
Boco 11113 1 0 Dec 24? 0:23/bin/sh./boco_monitor.sh
#ps-ef|grep boco|grep-v grep|awk ' {print ' kill-9 ' $ "
Kill-9 9884
Kill-9 9883
Kill-9 11112
Kill-9 11126
Kill-9 11125
Kill-9 9811
Kill-9 11113

As we can see, ps-ef|grep boco|grep-v grep lists the processes in the current host that are running in the process that contain the Boco keyword

and Ps-ef|grep boco|grep-v Grep|awk ' {print ' kill-9 ' $ $} ' lists the commands to kill these processes and prints them on the screen

After adding |sh after Ps-ef|grep boco|grep-v Grep|awk ' {print ' kill-9 "$", the commands are executed, and these processes are killed.

[Linux] commands for using awk to batch kill processes

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.