如何杀死与名称匹配的所有进程? [英] How to kill all processes matching a name?

查看:21
本文介绍了如何杀死与名称匹配的所有进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想杀死每个包含 amarok 一词的进程.我可以打印出我想要执行的命令.但是我如何真正让 shell 执行它们.即.

Say I want to kill every process containing the word amarok. I can print out the commands I want to execute. But how do I actually make the shell execute them. ie.

ps aux | grep -ie amarok | awk '{print "kill -9 " $2}'
Output:
kill -9 3052
kill -9 3071
kill -9 3076
kill -9 3077
kill -9 3079
kill -9 3080
kill -9 3082
kill -9 3083
kill -9 3084
kill -9 3085
kill -9 3086
kill -9 3087
kill -9 3088
kill -9 3089
kill -9 4031

推荐答案

来自 man 1 pkill

-f     The pattern is normally only matched against the process name.
       When -f is set, the full command line is used.

这意味着,例如,如果我们在 ps aux 中看到这些行:

Which means, for example, if we see these lines in ps aux:

apache   24268  0.0  2.6 388152 27116 ?        S    Jun13   0:10 /usr/sbin/httpd
apache   24272  0.0  2.6 387944 27104 ?        S    Jun13   0:09 /usr/sbin/httpd
apache   24319  0.0  2.6 387884 27316 ?        S    Jun15   0:04 /usr/sbin/httpd

我们可以使用 pkill -f 选项将它们全部杀死:

We can kill them all using the pkill -f option:

pkill -f httpd

这篇关于如何杀死与名称匹配的所有进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆