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 kill a specified process through the kill command in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to kill a specified process through the kill command in Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

One kills the specified process

It is now known that a curl thread is running and needs to be killed

Anggang@barry$ curl-y 30-Y 1-m 300-x 8.8.8.8 html_baidu 808-o html_baidu http://www.baidu.com

Total Received Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

00 00 00--:-0:00:21 -:-0

Ps-ef query run process

Yanggang@barry$ ps-ef | grep curl

Yanggang 10992 25473 0 14:11 pts/0 00:00:00 curl-y 30-Y 1-M300-x 8.8.8.8 pts/0 808-o html_baidu http://www.baidu.com

Yanggang 18591 11235 0 14:11 pts/1 00:00:00 grep-color=auto curl

Ps-ef queries and filters the process id:

Yanggang@barry$ ps-ef | grep curl

Yanggang 9201 25473 0 14:13 pts/0 00:00:00 curl-y 30-Y 1-M300-x 8.8.8.8 pts/0 808-o html_baidu http://www.baidu.com

Yanggang 13612 11235 0 14:13 pts/1 00:00:00 grep-color=auto curl

Yanggang@barry$ ps-ef | grep curl | grep-v grep | cut-c 15-20

25473

Ps-ef queries and filters the process id and kills the process:

Yanggang@barry$ ps-ef | grep curl

Yanggang 13390 28367 0 14:15 pts/3 00:00:00 curl-y 30-Y 1-m300-x 8.8.8.8 html_baidu http://www.baidu.com (before killing the process)

Yanggang 16946 11235 0 14:15 pts/1 00:00:00 grep-color=auto curl

Yanggang@barry$ ps-ef | grep curl | grep-v grep | cut-c 15-20

28367

Yanggang@barry$ ps-ef | grep curl | grep-v grep | cut-c 15-20 | xargs kill-9

Yanggang@barry$ ps-ef | grep curl

Yanggang 13072 11235 0 14:16 pts/1 00:00:00 grep-color=auto curl (no process after killing)

Or:

Kill-9 `ps-ef | grep "processname" | grep-v "grep" | awk'{print $2}'`

Kill batch process

For pid in $(ps-ef | grep curl | grep-v grep | cut-c 15-20); do (get process id array and loop kill all processes) echo $pid kill-9$ piddone

Post the source code:

#! / bin/shfor pid in $(ps-ef | grep curl | grep-v grep | cut-c 15-20) Do echo $pid kill-9$ piddone#while [!-z $(ps-ef | grep curl | grep-v grep | cut-c 9-15)] # do# ps-ef | grep curl | grep-v grep | cut-c 15-20 | xargs kill-killing ps-ef | grep curl | grep-v grep | cut-c 9-15 | xargs kill-9#done article on "how to kill a specified process through kill commands in Linux" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

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