Linux 如何通过管道给出杀死的论据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8653921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to give arguments to kill via pipe
提问by user567879
I need to search for a certain process and kill that process. I wrote a command like this:
我需要搜索某个进程并杀死该进程。我写了一个这样的命令:
ps -e | grep dmn | awk '{print }' | kill
Where the process name is dmn
. But it is not working. How can I find processes by name and kill
them.
进程名称在哪里dmn
。但它不起作用。如何按名称和kill
它们查找进程。
采纳答案by Daniel Persson
kill $(ps -e | grep dmn | awk '{print }')
回答by unutbu
回答by jcollado
In case there are multiple processes that you want to remove you can use this:
如果要删除多个进程,可以使用以下命令:
ps -efw | grep dmn | grep -v grep | awk '{print }' | xargs kill
Note: You need to remove grep process itself from the output, that's why grep -v grep
is used.
注意:您需要从输出中删除 grep 进程本身,这grep -v grep
就是使用的原因。
回答by Nishant
for procid in $(ps -aux | grep "some search" | awk '{print }'); do kill -9 $procid; done
hello friends .. we can do it using for loop .
你好朋友..我们可以使用for循环来做到这一点。
"Some search" is here any process name you want to search, for example "java" so let say count of java process is 200+ so killing one by one will be too typical .
“一些搜索”是您要搜索的任何进程名称,例如“java”,因此假设java进程的数量为200+,因此一个一个地杀死将太典型。
so you can use above command.
所以你可以使用上面的命令。
Thanks.
谢谢。
回答by pedmiston
Just adding on others, but I like using awk's regex features capacity:
只是添加其他人,但我喜欢使用 awk 的正则表达式功能容量:
kill $(ps | awk '/dmn/{print }')
回答by Deepak Sharma
Use pgrep
with -f option.
kill $(pgrep -f dmn)
pgrep
与 -f 选项一起使用。
kill $(pgrep -f dmn)
回答by Nathan F.
If you have the pidof
command on your system ( I know shells such as ZSH come with this by default, unless I'm mistaken), you could do something like.
如果您pidof
的系统上有该命令(我知道默认情况下,ZSH 之类的 shell 带有此命令,除非我弄错了),您可以执行类似的操作。
kill -9 $(pidof dmn)
回答by NotVeryPythonic
You might not need pipe
for this, if you have pidof
command and know the image name, I did it like this:
你可能不需要pipe
这个,如果你有pidof
命令并且知道图像名称,我是这样做的:
kill $(pidof synergyc)
$()
I understand this as it converts that output to a variable that kill can use, essentially like pipe would do. Shorter and easier to understand than some other options but also maybe less flexible and more direct.
$()
我理解这一点,因为它将输出转换为 kill 可以使用的变量,本质上就像管道一样。比其他一些选项更短、更容易理解,但也可能不那么灵活和更直接。