which java programs are running on local machine and remote machine ?
HI all
I have build a jconsole like tool which is text base means it gives all info about jvms in text format now i want two things to be done
1: list the jvms or java programs running on the local machine as jconsole does.
2: given the ip of computer i want to know which jvms or java programs are running on the computer and on which port they are running.
thanks in advance.
[408 byte] By [
JforJavaa] at [2007-11-27 1:38:09]

# 1
You could use Runtime.exec to launch the jps command in a subprocess and parse its output. jps can list remote JVMs if you have launched jstatd on the remote machine.
If you're using JDK 6, you could also use the Attach API <http://java.sun.com/javase/6/docs/technotes/guides/attach/index.html> to list the local JVMs.
In both cases you will typically only be able to list local JVMs that are running with the same user-id as your program.
I'm not sure what you mean by "on which port they are running".
Regards,
蒩monn McManus -- JMX Spec Lead -- http://weblogs.java.net/blog/emcmanus
# 2
thanks,
I am sorry i mean to say on which jmx port jvm is running eg we start jvm like this
java -Dcom.sun.management.jmxremote.port=9999 SampleTest
we need this port to connect to jvm jconsole too ask for port when we try to connect to remote jvm.
i have used attach API it works. but i want to list older versions also.
please explain me first approach or give at least a link.
-khizer
# 3
Here's a link for JPS:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
Note this excerpt:
The list of JVMs produced by the jps command may be limited by the permissions granted to the principal running the command. The command will only list the JVMs for which the principle has access rights as determined by operating system specific access control mechanisms.
This may not be an issue for you, but just in case you're not getting all the processes you expect, this may be why.
Regards,
Steve