silb78 silb78 - 5 months ago 67
Linux Question

Bash: kill process by name

I've got many java processes running with different jar files. I want to kill on explicit jar file process.

the following command doesn't work successfully:

sudo kill $(ps -ef | grep example.jar | awk '{print $2}')

It finds the correct PID, but can't kill it.


Try this:

ps -ef | grep PROCESS | grep -v grep | awk '{print $2}' | xargs kill -9

kills all pids matching the search term of "PROCESS".