java获取系统进程号

public static final int jvmPid() {
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
Field jvm = runtime.getClass().getDeclaredField("jvm");
jvm.setAccessible(true);
VMManagement mgmt = (VMManagement) jvm.get(runtime);
Method pidMethod = mgmt.getClass().getDeclaredMethod("getProcessId");
pidMethod.setAccessible(true);
int pid = (Integer) pidMethod.invoke(mgmt);
return pid;
} catch (Exception e) {
return -1;
}
}

  

上一篇:C#添加IIS站点


下一篇:cxf http 代码自动生成