@Test(groups="UNIX") public void testFindOwnPid() throws Exception { int ownpid = MonitorUtils.findOwnPid(); assertTrue(ownpid > 0, "ownpid=$ownpid"); assertTrue(MonitorUtils.isPidRunning(ownpid, "java"),"java is not running"); }
public static int findOwnPid() throws IOException { if (ownPid >= 0) return ownPid; String[] cmd = new String[]{"bash", "-c", "echo $PPID"}; Process process = Runtime.getRuntime().exec(cmd); String out = MonitorUtils.waitFor(process); ownPid = Integer.parseInt(out.trim()); return ownPid; }
MonitorUtils { public static int findOwnPid() throws IOException { if (ownPid >= 0) return ownPid; String[] cmd = new String[]{"bash", "-c", "echo $PPID"}; Process process = Runtime.getRuntime().exec(cmd); String out = MonitorUtils.waitFor(process); ownPid = Integer.parseInt(out.trim()); return ownPid; } }
MonitorUtils { public static int findOwnPid() throws IOException { if (ownPid >= 0) return ownPid; String[] cmd = new String[]{"bash", "-c", "echo $PPID"}; Process process = Runtime.getRuntime().exec(cmd); String out = MonitorUtils.waitFor(process); ownPid = Integer.parseInt(out.trim()); return ownPid; }  }
MonitorUtils { public static int findOwnPid() throws IOException { if (ownPid >= 0) return ownPid; String[] cmd = new String[]{"bash", "-c", "echo $PPID"}; Process process = Runtime.getRuntime().exec(cmd); String out = MonitorUtils.waitFor(process); ownPid = Integer.parseInt(out.trim()); return ownPid; }  static boolean isUrlUp(URL url); static boolean isPidRunning(int pid); static boolean isPidRunning(int pid, String regex); static List<Integer> getRunningPids(String regex); static List<Integer> getRunningPids(String regex, String excludingRegex); static MemoryUsage getMemoryUsage(int pid); static MemoryUsage getMemoryUsage(int pid, String clazzRegexOfInterest, int minInstancesOfInterest); static List<String> searchLog(File file, String grepOfInterest); static List<String> searchLog(File file, String grepOfInterest, Set<String> grepExclusions); static Process exec(String cmd); static String waitFor(Process process); static int findOwnPid(); }
MonitorUtils { public static int findOwnPid() throws IOException { if (ownPid >= 0) return ownPid; String[] cmd = new String[]{"bash", "-c", "echo $PPID"}; Process process = Runtime.getRuntime().exec(cmd); String out = MonitorUtils.waitFor(process); ownPid = Integer.parseInt(out.trim()); return ownPid; }  static boolean isUrlUp(URL url); static boolean isPidRunning(int pid); static boolean isPidRunning(int pid, String regex); static List<Integer> getRunningPids(String regex); static List<Integer> getRunningPids(String regex, String excludingRegex); static MemoryUsage getMemoryUsage(int pid); static MemoryUsage getMemoryUsage(int pid, String clazzRegexOfInterest, int minInstancesOfInterest); static List<String> searchLog(File file, String grepOfInterest); static List<String> searchLog(File file, String grepOfInterest, Set<String> grepExclusions); static Process exec(String cmd); static String waitFor(Process process); static int findOwnPid();  }