This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes can we Identify which java process? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we Identify which java process?" Watch "can we Identify which java process?" New topic

can we Identify which java process?

yo nara
Ranch Hand

Joined: Apr 03, 2002
Posts: 35
Suppose we are running two java (say swing appln) applications on a windows machine. In that case we can see two java processes running in windows task manager.
Can we identify which java process is running for which application?
Thanks in advance.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

There is no easy way to do this. If you want to know if one particular Java application is running you could use a marker when it starts up: possibly have it create a lock file or open a connection to a port.

Depending on the version of Windows you are using you might be able to use Windows Scripting Host's Shell object to start your Java app. from a WSF and get the PID. I've never tried it, but it theoretically should be possible. Of course it will mean you need to write two programs rather than one...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Naveen Vooka

Joined: Oct 13, 2004
Posts: 25
I am not sure why you want to do this but you can take the help of a profiler if your need is to increase the performance of a program by checking the consumption of system resources. Profiler is a computer program that can track the performance of another program by checking information´┐Żs collected while the code is executed. A profiler can identify the time used by or frequency of use of various portions of the second program. Typically this information is used to identify those portions of the second program that consume the most time. These time consuming parts are then targeted for optimisation. Also a profiler can be useful for debugging.

Naveen Vooka
DevSquare - Online Application Development
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
If the processes have different command lines, then it is possible.
Task Manager can't display full command line, but Sysinternals Process Explorer (enhanced task manager) or other similar program can.
[ September 27, 2005: Message edited by: Vlado Zajac ]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Except looking in the process explorer for a distinct "cmd.exe" has the same problem as looking for a distinct "java.exe". You still don't know which process is which.
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
Java 5.0 has a platform independent ps command: e.g., jps -l

That will show you which jvm is running which main class.

(jps is in the bin folder with java and javac so you can execute it directly)
[ September 28, 2005: Message edited by: Rick O'Shay ]
subject: can we Identify which java process?
Similar Threads
How to check if an application is already running?
Using Java, how to detect if an App is running
MyJar.jar gives process name as java.exe on windows Network is unreachable
Processing windows messages