Identify Java jdwp Debugger Assigned (Ephemeral) Port

随声附和 提交于 2019-11-30 15:15:44

From within VM:

    Properties props = sun.misc.VMSupport.getAgentProperties();
    System.out.println(props.getProperty("sun.jdwp.listenerAddress"));

From outside application:

    VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(PID);
    try {
        Properties props = vm.getAgentProperties();
        System.out.println(props.getProperty("sun.jdwp.listenerAddress"));
    } finally {
        vm.detach();
    }

Both are not a part of a standard. Applicable only to OpenJDK / Oracle JDK.

Maybe something you could start with.

netstat -tlnp

This gives you a list of all processes listening on a local TCP port. For example:

tcp    0    0 0.0.0.0:35688     0.0.0.0:*     LISTEN   26733/java
35688 - the ephemeral port
java  - the program name which is listening
26733 - the PID of the process 

If you need a finer granularity of the java processes you could use ps to gather informations about the process.

ps x -p 26733

could return something like

26733 pts/1 0:00 java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=0 Scratch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!