Question

I have an external Windows .exe that is actually Java application: Running the .exe starts javaw.exe, which in turn runs that Java application.

I didn't write that application and have no access to it through an API. I need to be able to kill it, however. So right now I just kill the Windows process javaw.exe, which is fine for a test machine running only that Java application but if I need finer granularity, I cannot currently do so.

My searches yielded suggestions such as Sysinternal's Process Explorer or the jps command in the JDK, but in the target systems for which I intend to provide the script, neither JDK nor Sysinternal's Process Explorer can be running.

Is there any other way that doesn't require an external tool? Does javaw.exe have a switch or command line option that lists Java processes? Is there a JRE version of jps?

Thanks.

Was it helpful?

Solution

I'd still suggest just killing the javaw.exe.

I can't see the downside, since it is the process you want to kill after all.

Remember that if you run multiple applications on the machine, they should each have a separate JVM instance. So you can still kill the specific application if you need to.

OTHER TIPS

The JDK (and possibly the JRE) ship with a utility called jps which can list all Java processes but also tell you the Main-Class currently running in that JVM. If JMX/JConsole is not an option, simply parsing the output of "jps -ml" and killing the appropriate process may work.

If you want to kill an entire JVM, just kill the javaw.exe process. Within a JVM there can be multiple Java threads but there's no way to poke into a JVM and terminate a thread unless the developer of the application provided a method to do so.

Based on your comment, multiple javaw.exe programs are running and you need to know which one to kill.

You might want to try connecting to each of the processes with JConsole and inspect the JVM. There may be enough clues to determine which one to kill. Once you've identified the profile of your application, you should be able to script the logic to make it easier in the future (use JMX to get most of the information provided by JConsole).

If the executable launches javaw then exits without providing any further information it seems like you need to use your scripting language to take a snapshot of running processes on the machine before launching the executable and after the executable has finished. Then you'll be able to deduce which is the new javaw process. What scripting language are you using?

Just another approach: if you have the jdk, there is a program called jvisualVM in the bin folder. It has nice info about each running JVM context. One of the things you can see is the PID of the VM, which I use to kill the process in Windows using task manager (on windows PID is not shown by default, but you can easily enable the column by going into view -> show columns )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top