/** * Gets whether the platform we are running on will cause us to treat * negative (i.e. invalid) PIDs as alive because of the format in which the * command line process monitor application for the system returns errors * for invalid PIDs * * @return True if a negative PID is treated as alive on this platform or we * cannot determine liveness for PIDs on this platform, false * otherwise */ public static boolean negativePidsTreatedAsAlive() { return isAlive(-1); }
return useFallbackPid(fallback); return useFallbackPid(fallback); try { } catch (NumberFormatException e) { return useFallbackPid(fallback);
/** * Determines whether a given PID is alive * * @param pid * PID * @return True if the given PID is alive or unknown, false if it is dead */ public static boolean isAlive(int pid) { String pidStr = Integer.toString(pid); try { List<String> data = getProcessInfo(pidStr); // Expect a line to contain the PID to indicate the process is // alive for (String lineData : data) { if (lineData.contains(pidStr)) return true; } // Did not find any lines mentioning the PID so we can safely // assume that process is dead return false; } catch (IOException e) { // If any error running the process to check for the live process // then our check failed and for safety we assume the process is // alive Sys.errlog .warn("Your platform does not support checking process liveness so TDB disk locations cannot be reliably locked to prevent possible corruption due to unsafe multi-JVM usage"); return true; } }
int pid = ProcessUtils.getPid(-1); writeProcessId(pid); return true;