jps
finds running Java processes by scanning through /tmp/hsperfdata_<username>
directory. Each HotSpot-based Java process creates a file in this directory with the name equal to the process ID.
The file /tmp/hsperfdata_<username>/<pid>
contains various counters exported by the JVM. These counters can be read by an external process. This is exactly how jstat
works. I described jvmstat performance counters in the JavaMagazine article.
So, jstat
can always read counters of a local Java process, but in order to be able to monitor a remote machine, jstatd
needs to be running.
jmap
, jstack
and jinfo
use Dynamic Attach mechanism. These utilities connect to the target JVM via UNIX-domain socket and send the corresponding command to the JVM. The command is executed by the remote JVM itself. Find more about Dynamic Attach in this answer and in this presentation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…