3

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.

jww
  • 97,681
  • 90
  • 411
  • 885
silb78
  • 139
  • 2
  • 11

3 Answers3

6

Try this:

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

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

piyushj
  • 1,546
  • 5
  • 21
  • 29
3

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.
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
0

Awk can perform what grep was doing here. This will search for pid of example.jar and then suppress the pid of awk itself.

kill $(ps -eaf |awk '/example.jar/ && !/awk/{print $2}')
P....
  • 17,421
  • 2
  • 32
  • 52