mirror of
https://gitee.com/arthas/arthas.git
synced 2024-11-30 03:07:37 +08:00
improve get pid logic
This commit is contained in:
parent
fdbe1a48ea
commit
86d1d4bfb7
@ -0,0 +1,32 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengyunabc 2018-09-30
|
||||
*
|
||||
*/
|
||||
public class ApplicationUtils {
|
||||
|
||||
private static String PID = "-1";
|
||||
|
||||
static {
|
||||
// https://stackoverflow.com/a/7690178
|
||||
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
|
||||
int index = jvmName.indexOf('@');
|
||||
|
||||
if (index > 0) {
|
||||
try {
|
||||
PID = Long.toString(Long.parseLong(jvmName.substring(0, index)));
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPid() {
|
||||
return PID;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import com.taobao.arthas.core.view.Ansi;
|
||||
|
||||
@ -46,7 +45,7 @@ public interface Constants {
|
||||
/**
|
||||
* 当前进程PID
|
||||
*/
|
||||
String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
|
||||
String PID = ApplicationUtils.getPid();
|
||||
|
||||
/**
|
||||
* 缓存目录
|
||||
|
Loading…
Reference in New Issue
Block a user