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
- Connecting to the JVM in question which in turn tells it
- From
/procfile system
Regarding the first alternative, is it using local JMX connection? Still, it must go to /proc for the pids.
- There is PID, so it must ask OS anyway
jpslists also itself
Regarding the second alternative, I feel this could be the correct one, because
- On the command line, there is either
-jarorMainClass /procknows wery well the PID- Before
jpsstarts 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).