How do jps, jinfo, jstat, jmap and jstack get info

2020-02-16 04:58发布

How does jps get information about all the local java processes? Does it connect to some local server process to fetch the information?

How do jinfo, jstat, jmap, and jstack get information about a local java process? Do they connect to some local server process(es) to fetch the information?

Is jstatd only used for providing remote access to local java processes, but not for providing local access to local java processes?

I am running Ubuntu. My question comes from https://stackoverflow.com/a/55669949/156458.

1条回答
啃猪蹄的小仙女
2楼-- · 2020-02-16 05:21

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.

查看更多
登录 后发表回答