惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Vercel News
Vercel News
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
H
Help Net Security
罗磊的独立博客
The Cloudflare Blog
J
Java Code Geeks
博客园 - 叶小钗
I
InfoQ
B
Blog
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
月光博客
月光博客
博客园_首页
雷峰网
雷峰网
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
美团技术团队
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美

博客园 - ABeen

[Database] Mongodb 分片集群 [Linux] vim状态栏配置 [Linux] Centos 添加开机启动脚本 [Linux] Docker 镜像及容器自动化思路 [Linux]Docker 容器时间与宿主机同步 [Linux] Tomcat java.lang.OutOfMemoryError: Java heap space [Linux] Nginx 反向代理配置 http headers 带下划线fields转发 [Linux] 非云环境的Ubuntu主机如何关闭Cloud-init [DataBase] MySql 查看实时日志 [Misc] ZSH 常用快捷键 [Database] MAC MySQL中文乱码问题 [Misc] python 开发vim 插件初步测试 [Tools] 多媒体视频处理工具FFmpeg [Linux] Ubuntu Server18 python3.7 虚拟环境 [Linux] 树莓派编译python3.7.4 [Linux] TMUX Python版本设置 arm树莓派Raspbian 下安装selenium+chrome 树莓派Raspbian系统密码 mac 终端查看端口命令
Linux 批量杀进程的命令
ABeen · 2019-06-25 · via 博客园 - ABeen

使用awk批量杀进程的命令:

ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}'|sh
#列出了当前主机中运行的进程中包含firefox关键字的进程
ps -ef | grep firefox | grep -v grep    
 
#列出了要kill掉这些进程的命令,并将之打印在了屏幕上 
ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}'
 
#后面加上|sh后,则执行这些命令,进而杀掉了这些进程
ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}' | sh

使用cut批量杀进程的命令:

ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -9
#列出了当前主机中运行的进程中包含firefox关键字的进程
ps -ef | grep firefox | grep -v grep 
      
#截取第9至15字符(进程id),列出了要kill掉这些进程的id,并将之打印在了屏幕上
ps -ef | grep firefox | grep -v grep | cut -c 9-15 
 
#后面加上'xargs kill -9'后,则执行这些命令,进而杀掉了这些进程
ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -9