in common/src/main/java/org/mvndaemon/mvnd/common/DaemonRegistry.java [282:313]
private static int getProcessId0() {
if (Os.current() == Os.LINUX) {
try {
final Path self = Paths.get("/proc/self");
if (Files.exists(self)) {
String pid = self.toRealPath().getFileName().toString();
if (pid.equals("self")) {
LOGGER.debug("/proc/self symlink could not be followed");
} else {
LOGGER.debug("loading own PID from /proc/self link: {}", pid);
try {
return Integer.parseInt(pid);
} catch (NumberFormatException x) {
LOGGER.warn("Unable to determine PID from malformed /proc/self link `{}`", pid);
}
}
}
} catch (IOException ignored) {
LOGGER.debug("could not load /proc/self", ignored);
}
}
String vmname = ManagementFactory.getRuntimeMXBean().getName();
String pid = vmname.split("@", 0)[0];
LOGGER.debug("loading own PID from VM name: {}", pid);
try {
return Integer.parseInt(pid);
} catch (NumberFormatException x) {
int rpid = new Random().nextInt(1 << 16);
LOGGER.warn("Unable to determine PID from malformed VM name `{}`, picked a random number={}", vmname, rpid);
return rpid;
}
}