mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
improve get pid logic
This commit is contained in:
@@ -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();
|
||||
|
||||
/**
|
||||
* 缓存目录
|
||||
|
||||
Reference in New Issue
Block a user