How to Kill Java Process in Windows, WITHOUT killing javaw.exe?
Asked Answered
G

6

5

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.

Gazelle answered 12/9, 2010 at 18:46 Comment(0)
F
3

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.

Following answered 12/9, 2010 at 19:1 Comment(4)
Thank you both, Jim and @Following -- +1 for both of you for explaining this issue to me. How would I know which javaw.exe to kill?Gazelle
Can't you look in Task Manager's Applications tab, then right-click on the relevant program and hit Go To Process. That'll give you the right javaw.exe.Bosson
What you need is a tool like Sysinternals Process Explorer. It'll allow you to see the parent processes and show you the full command line passed to javaw.exe.Lucchesi
@mikera, The downside is that on a server you affect the other Java apps by killing off the entire JVM.Complication
R
3

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.

Ruthanneruthe answered 13/9, 2010 at 11:23 Comment(0)
D
2

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.

Deutoplasm answered 12/9, 2010 at 19:5 Comment(0)
C
1

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).

Cowen answered 13/9, 2010 at 11:14 Comment(0)
C
0

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?

Catima answered 13/9, 2010 at 11:34 Comment(0)
F
0

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 )

Feu answered 12/3, 2012 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.