如何杀死与名字匹配的所有进程?

时间:2022-09-21 00:12:29

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.

说我想要杀死包含“amarok”这个词的每个进程。我可以打印出我想要执行的命令。但是我如何让shell执行它们。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

10 个解决方案

#1


292  

From man 1 pkill

从人1 pkill

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

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

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

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

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

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

pkill -f httpd

#2


167  

ps aux | grep -ie amarok | awk '{print $2}' | xargs kill -9 

xargs(1): xargs -- construct argument list(s) and execute utility. Helpful when you want to pipe in arguments to something like kill or ls or so on.

xargs(1): xargs——构造参数列表并执行实用程序。当你想要在参数中插入诸如kill或ls之类的东西时,这是很有帮助的。

#3


41  

use pgrep

使用pgrep

kill -9 $(pgrep amarok)

#4


21  

The safe way to do this is:

安全的做法是:

pkill -f amarok

#5


13  

I think this command killall is exactly what you need. The command is described as "kill processes by name".It's easy to use.For example

我认为这个命令killall正是您所需要的。该命令被描述为“按名称杀死进程”。它很容易使用。例如

killall chrome

This command will kill all process of Chrome.Here is a link about killall command

这个命令将杀死所有的Chrome进程。这里有一个关于killall命令的链接。

http://linux.about.com/library/cmd/blcmdl1_killall.htm

http://linux.about.com/library/cmd/blcmdl1_killall.htm

Hope this command could help you.

希望这个命令能帮到你。

#6


10  

pkill -x matches the process name exactly.

pkill -x完全匹配进程名。

pkill -x amarok

pkill -f is similar but allows a regular expression pattern.

pkill -f类似,但允许正则表达式模式。

Note that pkill with no other parameters (e.g. -x, -f) will allow partial matches on process names. So "pkill amarok" would kill amarok, amarokBanana, bananaamarok, etc.

注意,没有其他参数的pkill(例如-x, -f)将允许对进程名称进行部分匹配。所以“pkill amarok”会杀死amarok, amarokBanana, bananaamarok等。

I wish -x was the default behavior!

我希望-x是默认行为!

#7


4  

If you want to execute the output of a command, you can put it inside $(...), however for your specific task take a look at the killall and pkill commands.

如果您想执行一个命令的输出,您可以将它放入$(…)中,但是对于您的特定任务,请查看killall和pkill命令。

#8


3  

You can also evaluate your output as a sub-process, by surrounding everything with back ticks or with putting it inside $():

你也可以把你的输出作为一个子过程来评估,它周围的一切都是带着背的,或者是把它放进$():

`ps aux | grep -ie amarok | awk '{print "kill -9 " $2}'`

 $(ps aux | grep -ie amarok | awk '{print "kill -9 " $2}')     

#9


3  

try kill -s 9 ps -ef |grep "Nov 11" |grep -v grep | awk '{print $2}' To kill processes of November 11 or kill -s 9 ps -ef |grep amarok|grep -v grep | awk '{print $2}' To kill processes that contain the word amarok

你可以尝试杀死-s 9 ps -ef |grep -v grep -v grep -v grep -v grep -v grep -v grep -v grep -v grep - vgrep -v grep -v grep -v grep -v grep - vgrep - vgrep -v grep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep。

#10


0  

Maybe adding the commands to executable file, setting +x permission and then executing?

可能将命令添加到可执行文件,设置+x权限,然后执行?

ps aux | grep -ie amarok | awk '{print "kill -9 " $2}' > pk;chmod +x pk;./pk;rm pk

#1


292  

From man 1 pkill

从人1 pkill

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

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

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

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

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

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

pkill -f httpd

#2


167  

ps aux | grep -ie amarok | awk '{print $2}' | xargs kill -9 

xargs(1): xargs -- construct argument list(s) and execute utility. Helpful when you want to pipe in arguments to something like kill or ls or so on.

xargs(1): xargs——构造参数列表并执行实用程序。当你想要在参数中插入诸如kill或ls之类的东西时,这是很有帮助的。

#3


41  

use pgrep

使用pgrep

kill -9 $(pgrep amarok)

#4


21  

The safe way to do this is:

安全的做法是:

pkill -f amarok

#5


13  

I think this command killall is exactly what you need. The command is described as "kill processes by name".It's easy to use.For example

我认为这个命令killall正是您所需要的。该命令被描述为“按名称杀死进程”。它很容易使用。例如

killall chrome

This command will kill all process of Chrome.Here is a link about killall command

这个命令将杀死所有的Chrome进程。这里有一个关于killall命令的链接。

http://linux.about.com/library/cmd/blcmdl1_killall.htm

http://linux.about.com/library/cmd/blcmdl1_killall.htm

Hope this command could help you.

希望这个命令能帮到你。

#6


10  

pkill -x matches the process name exactly.

pkill -x完全匹配进程名。

pkill -x amarok

pkill -f is similar but allows a regular expression pattern.

pkill -f类似,但允许正则表达式模式。

Note that pkill with no other parameters (e.g. -x, -f) will allow partial matches on process names. So "pkill amarok" would kill amarok, amarokBanana, bananaamarok, etc.

注意,没有其他参数的pkill(例如-x, -f)将允许对进程名称进行部分匹配。所以“pkill amarok”会杀死amarok, amarokBanana, bananaamarok等。

I wish -x was the default behavior!

我希望-x是默认行为!

#7


4  

If you want to execute the output of a command, you can put it inside $(...), however for your specific task take a look at the killall and pkill commands.

如果您想执行一个命令的输出,您可以将它放入$(…)中,但是对于您的特定任务,请查看killall和pkill命令。

#8


3  

You can also evaluate your output as a sub-process, by surrounding everything with back ticks or with putting it inside $():

你也可以把你的输出作为一个子过程来评估,它周围的一切都是带着背的,或者是把它放进$():

`ps aux | grep -ie amarok | awk '{print "kill -9 " $2}'`

 $(ps aux | grep -ie amarok | awk '{print "kill -9 " $2}')     

#9


3  

try kill -s 9 ps -ef |grep "Nov 11" |grep -v grep | awk '{print $2}' To kill processes of November 11 or kill -s 9 ps -ef |grep amarok|grep -v grep | awk '{print $2}' To kill processes that contain the word amarok

你可以尝试杀死-s 9 ps -ef |grep -v grep -v grep -v grep -v grep -v grep -v grep -v grep -v grep - vgrep -v grep -v grep -v grep -v grep - vgrep - vgrep -v grep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep - vgrep。

#10


0  

Maybe adding the commands to executable file, setting +x permission and then executing?

可能将命令添加到可执行文件,设置+x权限,然后执行?

ps aux | grep -ie amarok | awk '{print "kill -9 " $2}' > pk;chmod +x pk;./pk;rm pk