tags:

views:

768

answers:

3

Is there a way to get name of the java app associated with a javaw.exe? Basically I need to write a tool, to check (daily) if a specific java app is running on our server (and if not the tool will email me).

I would like to do this in C#...but if there isn't a way I would be open to other suggestions.

I have read this question 265794 but that is more about modifying the java app itself...do all java app's really appear as javaw.ex, unless 'wrapped'??

+3  A: 

Check out jps. That will list the VMs running on your system, and identify the jar file or class invoked.

Brian Agnew
To follow up on this, do you know what is required for jps to run? I don't want to install the entire jdk. But if I copy just that exe to a diff directory and attempt to just run it I get the error "Exception in thread "main" java.lang.NoClassDefFoundError: sun/tools/jps/Jps"
Possibly the complete JRE
Brian Agnew
A: 

Well, the main class gets passed to javaw as a command line parameter, right? So if you use the info in this SO post, you should be able to find out what it's running.

Promit
A: 

You can find the list of running java applications under this folder: system-temp-folder/hsperfdata_*user* where system-temp-folder is the path to your system temp folder and user is the user that run the process. When a java process starts, it creates a file in that folder with the process-id as the name of the file. Each files containes binary data (including process name, i think). However, I think this is hard to read that binary file in C#. To find the process name you have two different solutions: First, you can use C# and system calls to find the process name (I don't know how you can do that in C#) Second, if you have access to a jdk folder, you may run jps and get the output. Actually, jps reads the files I have already mentioned and writes some human readable data to console.