您现在的位置是:网站首页> 编程资料编程资料
Linux中通过 kill命令 杀死指定进程_LINUX_操作系统_
2024-01-16
200人已围观
简介 Linux中通过 kill命令 杀死指定进程_LINUX_操作系统_
一 杀死指定进程
现知道有一个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 curl
yanggang 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.com
yanggang 18591 11235 0 14:11 pts/1 00:00:00 grep --color=auto curl
ps -ef 查询并过滤进程id:
yanggang@barry$ ps -ef | grep curl
yanggang 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.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 查询并过滤进程id,并杀死该进程:
yanggang@barry$ ps -ef | grep curl
yanggang 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 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 (杀死进程后,无此进程)
或者:
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 $pid kill -9 $pid done
贴出源码:
# !/bin/sh for pid in $(ps -ef | grep curl | grep -v grep | cut -c 15-20); do echo $pid kill -9 $pid done #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
相关内容
- linux Vi编辑器代码高亮设置及永久显示行号的方法_LINUX_操作系统_
- Linux下的命令行串口工具minicom安装和使用教程_LINUX_操作系统_
- 高手养成计划基础篇-Linux第一季_LINUX_操作系统_
- Linux shell 比较运算符详解_LINUX_操作系统_
- Linux下使用blkid命令查询设备及文件系统信息的方法_LINUX_操作系统_
- Linux多个网卡怎么添加永久路由?_LINUX_操作系统_
- Linux 统计代码行数的代码_LINUX_操作系统_
- 去吧皮卡丘精灵装备合成心得分享_手机游戏_游戏攻略_
- 刀塔传奇11月魂匣新英雄灰烬之灵属性技能觉醒装备资料介绍_手机游戏_游戏攻略_
- 去吧皮卡丘帝牙卢卡详细介绍_手机游戏_游戏攻略_
