1.获取JVM中运行的application的pid方法:
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
String jvmName = bean.getName();
String pid = jvmName.split("@")[0];
2.获取JVM通过exec()执行的其它程序的pid方法:
类似如下这种:
Process process = Runtime.getRuntime().exec( "calc");
解决方案:
http://golesny.de/p/code/javagetpid(如果不存在请访问:http://blog.csdn.net/motrsky/article/details/74984156)
https://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id