How can a Java program get its own process ID?

后端 未结 22 2068
梦毁少年i
梦毁少年i 2020-11-22 03:47

How do I get the id of my Java process?

I know there are several platform-dependent hacks, but I would prefer a more generic solution.

22条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 04:32

    The latest I have found is that there is a system property called sun.java.launcher.pid that is available at least on linux. My plan is to use that and if it is not found to use the JMX bean.

提交回复
热议问题