获取当前进程的pid

时间:2022-03-19 23:09:38

获取当前进程的pid



import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean; public static final int getProcessID() {
try {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
return Integer.valueOf(runtimeMXBean.getName().split("@")[0]).intValue();
}catch (Exception ex){
logger.error(ex.getMessage(),ex);
return 0;
}
}