Linux中通过 kill命令 杀死指定进程
一 杀死指定进程
现知道有一个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
相关文章

集成系统级Claw模式! Deepin 官宣发布 25.1 版本
deepin操作系统发布了最新的 25.1 版本更新,该版本基于 deepin 25 正式版积累的多轮内测成果,在 AI 能力、内核版本、桌面环境、文件管理器以及系统安全等方面进行了更新2026-04-13
又一代老硬件退场! Linux 内核正式放弃Intel 486 CPU
在过去的几十年间,CPU 的架构已经经历了飞速发展,x86 系列就是其中之一,而 i486 则属于该系列中的一个,当前,i486 的CPU处理器已经够老,从 Linux 7.1 开始将不再有对2026-04-09
我把 Linux 中最常用、最实用、最常被问到的命令按照实际使用场景分类整理,方便你快速查阅和记忆,内容覆盖日常运维、开发调试、性能分析、文件处理、网络、安全、系统管2026-04-08
一分钟内检查Linux服务器性能? 9个性能检测常用的基本命令
今天我们来看看Linux系统中用于性能监控的一系列命令,这些命令可以快速查看机器的负载情况,详细请看下文介绍2026-03-18
Linux作为操作系统领域灵活性和可定制性的基石,提供了大量满足不同用户需求的发行版,今天分享适合高级用户的15款Linux发行版2026-03-10
开箱即用? 这4个高手级Linux发行版远没你想象的那么安全易用
如果你正在纠结用哪个发行版?零基础新手别被“高端”“极客”“声明式”这些词冲昏头脑,先用好用的,再慢慢进阶2026-03-10
这几款SSH工具真的够用了! Linux好用的ssh工具推荐
在Linux上使用SSH,您需要安装一个SSH客户端,今天整理找到的8 款 SSH / 终端工具,从免费开源到企业级商用,从轻量化命令行到一站式工具箱,每款都做了介绍与对比,希望能2026-03-09
在Linux系统下有两种用户,即高级用户root,普通用户,高级用户root可以在系统中做任何事情,普通用户仅可在Linux系统中做有限的事情,下面我们就来看看切换方法2026-02-28
揭秘当前登录用户的身份! Linux中使用logname命令的技巧
logname命令就是这样一个简单但强大的工具,它能帮助我们轻松获取当前登录用户的用户名,今天,我们就来深入探索一下这个命令的工作原理、使用方法和最佳实践2026-02-26
在 Linux 系统中,DNS 缓存是一种将域名和 IP 地址映射关系缓存在本地的机制,可以加快域名解析速度,并减轻 DNS 服务器的负载2026-02-26




最新评论