I have a .jar
file which is notorious for malfunctions. When a malfunction occurs, only a restart helps. I have a way to detect that malfunctions (reading the log-file of said .jar
) So I want to write a script, that kills the process whenever the malfunction occurs. The problem is:
confus@confusion:~$ ps -A
...
4438 ? 00:00:00 java
4439 ? 00:00:00 java
4443 ? 00:00:00 java
...
The process name of all running .jar
s is naturally "java". How do I find out, which of these "java"-processes is the one I want to kill, i.e. the one running foobar.jar
?
Best Answer
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:To easily reuse the pid in a script, you could run it in terse mode: