Reputation: 648
I am wondering, how does JPS tool get the name of the main class it is executed within jvm process. It is
jps -l
123 package.MainClass
456 /path/example.jar
I am talking specifically about Linux (I am not interested in Windows, and I have no Win machine to experiment on).
I could think of 2 ways
/proc
file systemRegarding the first alternative, is it using local JMX connection? Still, it must go to /proc
for the pids.
jps
lists also itselfRegarding the second alternative, I feel this could be the correct one, because
-jar
or MainClass
/proc
knows wery well the PIDjps
starts doind something, it has own folder in /proc
But, I am facing little problem here. When java command is very long (e.g. there is extremely long -classpath
parameter), the information about the command line does not fit into space reserved for it in /proc
. My system has 4kB for it, and what I learned elsewhere, this is hardwired in OS code (changing it requires kernel compilation). However, even in this case jps
is still able to get that main class somewhere. How?
I need to find quicker way to get JVM process than calling jps
. When system is quite loaded (e.g. when number of JVMs start), jps
got stuck for several seconds (I have seen it waiting for ~30s).
Upvotes: 1
Views: 2815
Reputation: 98334
jps
scans through /tmp/hsperfdata_<username>/<pid>
files that contain monitors and counters of running JVMs. The monitor named sun.rt.javaCommand
contains the string you are looking for.
To find out the format of PerfData file you'll have to look into JDK source code.
Upvotes: 4