How can I know, how many JVM is running?

Hi,How can I know, how many JVM is running in the same time?
[74 byte] By [orodsema] at [2007-11-26 15:47:28]
# 1
In Java? You can not.With JNI (or manually using TaskManager) you could take a guess by counting the instances of java.exe.Why do you want this?
mlka at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 2
> Why do you want this?Agree sounds like an odd question.
kajbja at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 3
No way even using JNI. Even if you'll count java.exe one can use javaw.exe or rename executable to random and use say xxx.exe. Also one can create it's own JVM so even memory analysis became useless.BTW I repeat main question - why do you need to count JVMs? Just for fun?
Michael.Nazarov@sun.coma at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 4
> java.exeOn our application server a lot of Java VM's are running but not a single java.exe!(HInt: it is Linux.)
BIJ001a at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 5
Yes I should have put "guess" in bold and double-underlined.And I should have placed a star by java.exe with the text:* And all other known names of the Java launcher, such as javaw, and OS variants.
mlka at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 6
* And all other known, unknown and custom names of the Java launcher:)
Michael.Nazarov@sun.coma at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 7

Well, just to through in my two cents, on most unix/linux variants you can identify processes that have a handle to a specific file, so the count of processes that currently have a file handle to rt.jar (in all of its various versions installed on the machine) should give you a somewhat accurate count of the running JVMs (unless someone is manually looking at one of the rt.jars with an editor or something).

;-)

But, I don't suggest this as the overhead in finding this out is not insignificant, and once again, why do you need the info.

masijade.a at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 8

> * And all other known, unknown and custom names of

> the Java launcher

> :)

I'll repeat: Guess. Not even an educated guess, shouting four might be just as reliable. But if you have a degree of control over the environment, and I think for many developer/desktops, this will give a reasonable acceptable result.

Message was edited by:

mlk

mlka at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 9

> Well, just to through in my two cents, on most

> unix/linux variants you can identify processes that

> have a handle to a specific file, so the count of

> processes that currently have a file handle to rt.jar

> (in all of its various versions installed on the

> machine) should give you a somewhat accurate count of

> the running JVMs (unless someone is manually looking

> at one of the rt.jars with an editor or something).

A good idea, but my app-server process does not appear to have *any* jar open.

[ebank2@giskard oc4j]$ ls -l /proc/10038/fd|grep jar

[ebank2@giskard oc4j]$ ps -p 10038

PID TTY TIME CMD

10038 ?00:00:01 java

[ebank2@giskard oc4j]$ ps -p 10038 -f

UIDPID PPID C STIME TTY TIME CMD

ebank210038 10034 0 Jan08 ?00:00:01 java -DUSR=ivan -classpath .:/opt/mqm/java/lib/com.ibm.mq.jar:/opt/mqm/j

BIJ001a at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...
# 10

> A good idea, but my app-server process does not

> appear to have *any* jar open.

>

>

> [ebank2@giskard oc4j]$ ls -l /proc/10038/fd|grep jar

> [ebank2@giskard oc4j]$ ps -p 10038

>PID TTY TIME CMD

> 038 ?00:00:01 java

> [ebank2@giskard oc4j]$ ps -p 10038 -f

> UIDPID PPID C STIME TTY TIME CMD

> ebank210038 10034 0 Jan08 ?00:00:01 java

> -DUSR=ivan -classpath

> .:/opt/mqm/java/lib/com.ibm.mq.jar:/opt/mqm/j

>

Aaaaaaaahhhhhhhh, Oh well. It was worth a try. I hadn't tried it myself, but I didn't figure that they would open the file everytime they needed to load a class, but I guess they do.

masijade.a at 2007-7-8 22:06:57 > top of Java-index,Java Essentials,Java Programming...