位置:- 正文

Linux中通过 kill命令 杀死指定进程(linux killall)

编辑:rootadmin
这篇文章主要介绍了Linux中通过 kill命令 杀死指定进程,需要的朋友可以参考下... 16-11-21

推荐整理分享Linux中通过 kill命令 杀死指定进程(linux killall),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:linux命令kill,linux中kill命令是做什么用的?,linux中kill命令详解,linux中killed,linux中killed,linux kill -s,linux中killed,linux命令kill怎么用,内容如对您有帮助,希望把文章链接给更多的朋友!

一 杀死指定进程

Linux中通过 kill命令 杀死指定进程(linux killall)

现知道有一个curl线程正在运行,需要杀死anggang@barry$ curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.baidu.com % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0

ps -ef 查询运行进程yanggang@barry$ ps -ef | grep curlyanggang 10992 25473 0 14:11 pts/0 00:00:00 curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.baidu.comyanggang 18591 11235 0 14:11 pts/1 00:00:00 grep --color=auto curlps -ef 查询并过滤进程id:yanggang@barry$ ps -ef | grep curlyanggang 9201 25473 0 14:13 pts/0 00:00:00 curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.baidu.comyanggang 13612 11235 0 14:13 pts/1 00:00:00 grep --color=auto curlyanggang@barry$ ps -ef | grep curl | grep -v grep | cut -c 15-2025473ps -ef 查询并过滤进程id,并杀死该进程:yanggang@barry$ ps -ef | grep curlyanggang 13390 28367 0 14:15 pts/3 00:00:00 curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.baidu.com (杀死进程前)yanggang 16946 11235 0 14:15 pts/1 00:00:00 grep --color=auto curlyanggang@barry$ ps -ef | grep curl | grep -v grep | cut -c 15-2028367yanggang@barry$ ps -ef | grep curl | grep -v grep | cut -c 15-20 | xargs kill -9yanggang@barry$ ps -ef | grep curlyanggang 13072 11235 0 14:16 pts/1 00:00:00 grep --color=auto curl (杀死进程后,无此进程)

或者: kill -9 `ps -ef|grep “processname” | grep -v "grep"|awk '{print $2} '`

二 杀死批量进程

for pid in $(ps -ef | grep curl | grep -v grep | cut -c 15-20); do (获取进程id数组,并循环杀死所有进程)echo $pidkill -9 $piddone

贴出源码:

# !/bin/shfor pid in $(ps -ef | grep curl | grep -v grep | cut -c 15-20); doecho $pidkill -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 -9# ps -ef | grep curl | grep -v grep | cut -c 9-15 | xargs kill -9#done
本文链接地址:https://www.jiuchutong.com/zhishi/273359.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/273360.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络