3

ps -aux | less displays

java -jar /var/appname.jar

Now I'm killing it by

killall -9 java

But if there is also another java process java -jar /var/anotherappname.jar how to kill only the first one?

Ekaterina
  • 131

1 Answers1

4

I'd suggest using pkill, with the -f flag to match against the whole command:

pkill -f /var/appname.jar

Test first with

pgrep -af /var/appname.jar

From man pkill:

   -f, --full
          The pattern is normally only matched against the  process  name.
          When -f is set, the full command line is used.
steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • I can't get pgrep to work if it's just a class name, such as one running through the IDE. Anyone have success? e.g. 26126 ?? 0:07.15 java [...] com.github.MySillyClass.

    Searching for the process using pgrep -af com.github.MySillyClass isn't working.

    – tresf Oct 09 '19 at 02:45