JPS工具如何获取正在执行的主类或jar的名称 [英] How does JPS tool get the name of the main class or jar it is executing

查看:197
本文介绍了JPS工具如何获取正在执行的主类或jar的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,JPS工具如何获得它在jvm进程中执行的主类的名称。它是

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

我正在谈论Linux(我对Windows不感兴趣,我没有Win机器可以试验)。

I am talking specifically about Linux (I am not interested in Windows, and I have no Win machine to experiment on).

我能想到两种方式


  1. 连接到JVM in反过来告诉它的问题

  2. 来自 / proc 文件系统

  1. Connecting to the JVM in question which in turn tells it
  2. From /proc file system

关于第一种选择,它是否使用本地JMX连接?仍然,它必须转到 / proc 为pids。

Regarding the first alternative, is it using local JMX connection? Still, it must go to /proc for the pids.


  1. 有PID ,所以它必须要求操作系统

  2. jps 列表本身

  1. There is PID, so it must ask OS anyway
  2. jps lists also itself

关于第二种选择,我觉得这可能是正确的,因为

Regarding the second alternative, I feel this could be the correct one, because


  1. 在命令行中,有 -jar MainClass

  2. / proc 非常了解PID

  3. jps 启动之前,它有自己的文件夹 / proc

  1. On the command line, there is either -jar or MainClass
  2. /proc knows wery well the PID
  3. Before jps starts doind something, it has own folder in /proc

但是,我面对的很少问题在这里。当java命令很长时(例如,有非常长的 -classpath 参数),有关命令行的信息不适合的/ proc 。我的系统有4kB,而我在其他地方学到的,这是在OS代码中硬连线(改变它需要内核编译)。但是,即使在这种情况下, jps 仍然能够在某处获得该主类。如何?

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?

我需要找到更快的方法来获取JVM进程而不是调用 jps 。当系统负载很重时(例如当JVM启动时), jps 卡住了几秒钟(我已经看到它等待了~30秒)。

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).

推荐答案

jps 扫描 / tmp / hsperfdata_< username> /< ; pid> 包含运行JVM的监视器和计数器的文件。名为 sun.rt.javaCommand 的监视器包含您要查找的字符串。

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.

查找格式您必须查看的PerfData文件 JDK源代码

To find out the format of PerfData file you'll have to look into JDK source code.

这篇关于JPS工具如何获取正在执行的主类或jar的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆