@Test public void assertGetPidByProcess() throws Exception { if (OS.isFamilyUnix()) { Process process = Runtime.getRuntime().exec("echo 123"); long pid = SaturnExecuteWatchdog.getPidByProcess(process); assertThat(pid).isGreaterThan(0); } }
public static long getPidByProcess(Process p) { if (!OS.isFamilyUnix()) { return INVALID_PID; } try { String clsName = "java.lang.UNIXProcess"; Class<?> cls = Class.forName(clsName); Field field = cls.getDeclaredField("pid"); field.setAccessible(true); Object pid = field.get(p); LogUtils.debug(log, LogEvents.ExecutorEvent.COMMON, "Get Process Id: {}", pid); return Long.parseLong(pid.toString()); } catch (Exception e) { LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "Getting pid error: {}", e.getMessage(), e); return INVALID_PID; } }
SaturnExecuteWatchdog extends ExecuteWatchdog { public static long getPidByProcess(Process p) { if (!OS.isFamilyUnix()) { return INVALID_PID; } try { String clsName = "java.lang.UNIXProcess"; Class<?> cls = Class.forName(clsName); Field field = cls.getDeclaredField("pid"); field.setAccessible(true); Object pid = field.get(p); LogUtils.debug(log, LogEvents.ExecutorEvent.COMMON, "Get Process Id: {}", pid); return Long.parseLong(pid.toString()); } catch (Exception e) { LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "Getting pid error: {}", e.getMessage(), e); return INVALID_PID; } } }
SaturnExecuteWatchdog extends ExecuteWatchdog { public static long getPidByProcess(Process p) { if (!OS.isFamilyUnix()) { return INVALID_PID; } try { String clsName = "java.lang.UNIXProcess"; Class<?> cls = Class.forName(clsName); Field field = cls.getDeclaredField("pid"); field.setAccessible(true); Object pid = field.get(p); LogUtils.debug(log, LogEvents.ExecutorEvent.COMMON, "Get Process Id: {}", pid); return Long.parseLong(pid.toString()); } catch (Exception e) { LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "Getting pid error: {}", e.getMessage(), e); return INVALID_PID; } } SaturnExecuteWatchdog(final long timeout, final String jobName, final int jobItem, final String execParam,
			final String executorName); }
SaturnExecuteWatchdog extends ExecuteWatchdog { public static long getPidByProcess(Process p) { if (!OS.isFamilyUnix()) { return INVALID_PID; } try { String clsName = "java.lang.UNIXProcess"; Class<?> cls = Class.forName(clsName); Field field = cls.getDeclaredField("pid"); field.setAccessible(true); Object pid = field.get(p); LogUtils.debug(log, LogEvents.ExecutorEvent.COMMON, "Get Process Id: {}", pid); return Long.parseLong(pid.toString()); } catch (Exception e) { LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "Getting pid error: {}", e.getMessage(), e); return INVALID_PID; } } SaturnExecuteWatchdog(final long timeout, final String jobName, final int jobItem, final String execParam,
			final String executorName); String getJobName(); int getJobItem(); String getExecParam(); long getPid(); String getExecutorName(); boolean isTimeout(); boolean isForceStop(); @Override synchronized void start(final Process processToMonitor); @Override synchronized void destroyProcess(); @Override synchronized void timeoutOccured(final Watchdog w); @Override synchronized boolean killedProcess(); static long getPidByProcess(Process p); }
SaturnExecuteWatchdog extends ExecuteWatchdog { public static long getPidByProcess(Process p) { if (!OS.isFamilyUnix()) { return INVALID_PID; } try { String clsName = "java.lang.UNIXProcess"; Class<?> cls = Class.forName(clsName); Field field = cls.getDeclaredField("pid"); field.setAccessible(true); Object pid = field.get(p); LogUtils.debug(log, LogEvents.ExecutorEvent.COMMON, "Get Process Id: {}", pid); return Long.parseLong(pid.toString()); } catch (Exception e) { LogUtils.error(log, LogEvents.ExecutorEvent.COMMON, "Getting pid error: {}", e.getMessage(), e); return INVALID_PID; } } SaturnExecuteWatchdog(final long timeout, final String jobName, final int jobItem, final String execParam,
			final String executorName); String getJobName(); int getJobItem(); String getExecParam(); long getPid(); String getExecutorName(); boolean isTimeout(); boolean isForceStop(); @Override synchronized void start(final Process processToMonitor); @Override synchronized void destroyProcess(); @Override synchronized void timeoutOccured(final Watchdog w); @Override synchronized boolean killedProcess(); static long getPidByProcess(Process p);  }