I would like to kill a java process based on the command name... Whats the best way to do it?
(i.e. when you do ps -f
the name in the CMD
column).
I would like to kill a java process based on the command name... Whats the best way to do it?
(i.e. when you do ps -f
the name in the CMD
column).
Simples, use pkill
pgrep, pkill - look up or signal processes based on name and other attributes
One way is with killall:
killall - kill processes by name
You can do it with killall NAME.
Also, you can use the option
-e,--exact require exact match for very long names
If you want a quick script that will kill it in one line, try this:
kill `ps aux | awk '$1 ~ "java" {print $2}'`
Where "java" is in quotes, make sure you change it to whatever name Java is running under. You can check that by running ps aux
If it won't die, you can use kill -9
instead, which ensures execution.
kill -9 `ps aux | awk '$1 ~ "java" {print $2}'`