How can I find out, which jar-files java is currently running (and their PIDs)?

You can run the lsof command, which lists which processes has open files, with your jar file given as an argument. An example viewing a file with less:

egil@mutter:~$ lsof foo.c
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
less    18871 egil    4r   REG    8,2        0 53862540 foo.c
egil@mutter:~$

To easily reuse the pid in a script, you could run it in terse mode:

egil@mutter:~$ lsof -t foo.c
18871

Using ps ax will help.

It will display the process tree in a BSD style which simply shows way more information.

To find your particular process you just have to grep for the JAR name. ps ax | grep JARNAME will do it.

Tags:

Java

Process

Kill