use of sun.management.VMManagement in project jdk8u_jdk by JetBrains.
the class ProcessTools method getProcessId.
/**
* Get the process id of the current running Java process
*
* @return Process id
*/
public static int getProcessId() throws Exception {
// Get the current process id using a reflection hack
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
Field jvm = runtime.getClass().getDeclaredField("jvm");
jvm.setAccessible(true);
VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
pid_method.setAccessible(true);
int pid = (Integer) pid_method.invoke(mgmt);
return pid;
}
use of sun.management.VMManagement in project quasar by puniverse.
the class ProcessUtil method getCurrentPid.
public static int getCurrentPid() {
try {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
jvmField.setAccessible(true);
VMManagement vmManagement = (VMManagement) jvmField.get(runtimeMXBean);
Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
getProcessIdMethod.setAccessible(true);
return (Integer) getProcessIdMethod.invoke(vmManagement);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of sun.management.VMManagement in project jdk8u_jdk by JetBrains.
the class JdpController method getProcessId.
// Get the process id of the current running Java process
private static Integer getProcessId() {
try {
// Get the current process id using a reflection hack
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
Field jvm = runtime.getClass().getDeclaredField("jvm");
jvm.setAccessible(true);
VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
pid_method.setAccessible(true);
Integer pid = (Integer) pid_method.invoke(mgmt);
return pid;
} catch (Exception ex) {
return null;
}
}
Aggregations