Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill process by name using Bash? [duplicate]

Tags:

linux

bash

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.

like image 229
silb78 Avatar asked Jun 04 '26 00:06

silb78


2 Answers

Try this:

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

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

like image 163
piyushj Avatar answered Jun 06 '26 15:06

piyushj


you can use killall which allows you to kill processes by name:

killall -ir example.jar

the options:

  • -i : interactive (asks confirmation for each process whether or not to kill it)
  • -r : allows you to specify a regex. killall will try to kill all matching.
like image 42
Chris Maes Avatar answered Jun 06 '26 15:06

Chris Maes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!