Bash:用管道杀死

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16931172/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:36:53  来源:igfitidea点击:

Bash: kill with pipe

bashpipe

提问by Bin Zhou

Trying to killvery process related to Java. Is there a way to use pipe for it? I have tried

尝试kill与Java相关的非常进程。有没有办法使用管道?我试过了

ps -e|grep "java"|kill

ps -e|grep "java"|kill

and

ps -e|grep "java"|xargs kill

ps -e|grep "java"|xargs kill

Neither works.

两者都不起作用。

回答by perreal

pgrepis the right tool for grepping processes:

pgrep是 grepping 进程的正确工具:

kill $(pgrep -f java)

the -fflag in pgrepis for matching against the full command line used to execute a process.

pgrep 中-f标志用于匹配用于执行进程的完整命令行。

回答by antak

There is, but this is easier (presuming your system has killall):

有,但这更容易(假设您的系统有killall):

killall java

回答by uli42

You can also use pkill java. pkillis pgrepand killcombined into one command.

您也可以使用pkill java. pkillpgrepkill组合成一个命令。