How can I kill a process based on its command line arguments?
killall, pgrep, and pkill seem to only work based on the process name.
I need this to be able to differentiate between a number of applications running inside Java virtual machines, where java is the process name for all of them and the actual application name can be found by looking at the command line arguments.
This can be done manually with ps aux | grep myapp.jar and then manually killing the pid from the output, but I'd like a command to do something equivalent automatically.
bash: syntax error near unexpected token ';'... It does work in a case statement when the ampersand is followed by;;... maybe you are using a different shell(?) – Peter.O Feb 07 '12 at 20:07zsh, which supports the syntax I used. Leaving it out works in both though, so I removed it – Michael Mrozek Feb 08 '12 at 06:36zshusers than elsewhere - I only seem to findzshusers here. – jw013 Feb 09 '12 at 06:58pkill -f 'sleep .0'would killsleep 30andsleep 60but notsleep 35. If you want to match any parameter dopkill -f 'sleep .* myArg'. – Ryan Shillington Jul 02 '21 at 14:51pkill -f ".*java .* org.apache.rocketmq.console.App"This help to kill a java process with given args. – Eric Aug 04 '21 at 09:43