Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: kill with pipe

Tags:

bash

pipe

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

ps -e|grep "java"|kill

and

ps -e|grep "java"|xargs kill

Neither works.

like image 244
Bin Zhou Avatar asked Dec 01 '22 03:12

Bin Zhou


2 Answers

pgrep is the right tool for grepping processes:

kill $(pgrep -f java)

the -f flag in pgrep is for matching against the full command line used to execute a process.

like image 141
perreal Avatar answered Dec 05 '22 15:12

perreal


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

killall java
like image 31
antak Avatar answered Dec 05 '22 13:12

antak