how to change the name of a Java application process?

后端 未结 10 2326
借酒劲吻你
借酒劲吻你 2020-11-27 04:51

When executing a Java application the process name given to it is usually java.exe or javaw.exe. But how can I make it be called by the name of my

10条回答
  •  时光说笑
    2020-11-27 05:11

    You can do this with an LD_PRELOAD shim: https://github.com/airlift/procname

    The shim simply calls the Linux-specific prctl() when the process starts:

    static void __attribute__ ((constructor)) procname_init()
    {
       prctl(PR_SET_NAME, "myname");
    }
    

    The call has to happen on the main thread, so it isn't possible to do this from Java or even with a JVMTI agent, since those happen on a different thread.

提交回复
热议问题