public static void main(String[] args) { Set<Map.Entry<Integer, String>> set = getProcessTable().entrySet(); System.out.println("** Got " + set.size() + " process entries"); for (Map.Entry<Integer, String> e : set) { System.out.printf("%d %s%n", e.getKey(), e.getValue()); } if(args.length > 0) { System.out.printf("Jps.isPid(%s) ==> %b%n", args[0], Jps.isPid(Integer.parseInt(args[0]))); } }
static public Map<Integer, String> getProcessTable() { return new Jps().pidMap; }
public static void main(String[] args) { System.out.println("** Got " + set.size() + " process entries"); if (args.length > 0) { int pid = Integer.parseInt(args[0]); boolean legal = Jps.isPid(Integer.parseInt(args[0])); System.out.printf("Jps.isPid(%s) ==> %b%n", args[0], legal); getDump(pid); } else { for (Map.Entry<Integer, String> e : set) { System.out.printf("%d %s%n", e.getKey(), e.getValue()); } System.out.println(getDump()); System.out.println("XXXXX"); } }
/** * return the platform-specific process-id of a JVM * @param mainClassName The main class - this is how we identify the right JVM. * You can pass in a fully-qualified name or just the classname. * E.g. com.sun.enterprise.glassfish.bootstrap.ASMain and ASMain work the same. * @return the process id if possible otherwise 0 */ static public List<Integer> getPid(String mainClassName) { if (mainClassName == null) return Collections.emptyList(); String plainName = plainClassName(mainClassName); Jps jps = new Jps(); List<Integer> ints = new LinkedList<Integer>(); Set<Map.Entry<Integer, String>> set = jps.pidMap.entrySet(); Iterator<Map.Entry<Integer, String>> it = set.iterator(); while (it.hasNext()) { Map.Entry<Integer, String> entry = it.next(); String valueFull = entry.getValue(); String valuePlain = plainClassName(valueFull); if (mainClassName.equals(valueFull) || plainName.equals(valuePlain)) // got a match! ints.add(entry.getKey()); } return ints; }
if (!isJps(sublines[1])) { pidMap.put(sublines[1], aPid);
/** * This is a bit tricky. "jps -l" will return a FQ classname * But it also might return a path if you start with "java -jar" * E.g. <pre> 2524 sun.tools.jps.Jps 5324 com.sun.enterprise.glassfish.bootstrap.ASMain 4120 D:\glassfish5\glassfish\bin\..\modules\admin-cli.jar </pre> * If there is a path -- then there is no classname and vice-versa * @param s * @return */ private static String plainClassName(String s) { if(s == null) return null; if(hasPath(s)) return stripPath(s); if (!s.contains(".") || s.endsWith(".")) return s; // we handled a/b/c/foo.jar // now let's handle foo.jar if(s.endsWith(".jar")) return s; return s.substring(s.lastIndexOf('.') + 1); }
public static void main(String[] args) { Set<Map.Entry<String, Integer>> set = getProcessTable().entrySet(); System.out.println("** Got " + set.size() + " process entries"); for (Map.Entry<String, Integer> e : set) { System.out.printf("%d %s\n", e.getValue(), e.getKey()); } }
/** * Kill the JVM with the given main classname. The classname can be * fully-qualified or just the classname (i.e. without the package name * prepended). * * @param pid * @return a String if the process was not killed for any reason including * if it does not exist. Return null if it was killed. */ public static String killJvm(String classname) { List<Integer> pids = Jps.getPid(classname); StringBuilder sb = new StringBuilder(); int numDead = 0; for (int p : pids) { String s = kill(p); if (s != null) sb.append(s).append('\n'); else ++numDead; } String err = sb.toString(); if (err.length() > 0 || numDead <= 0) return Strings.get("ProcessUtils.killjvmerror", err, numDead); return null; }
public static void main(String[] args) { System.out.println("** Got " + set.size() + " process entries"); if (args.length > 0) { int pid = Integer.parseInt(args[0]); boolean legal = Jps.isPid(Integer.parseInt(args[0])); System.out.printf("Jps.isPid(%s) ==> %b%n", args[0], legal); getDump(pid); } else { for (Map.Entry<Integer, String> e : set) { System.out.printf("%d %s%n", e.getKey(), e.getValue()); } System.out.println(getDump()); System.out.println("XXXXX"); } }
/** * return the platform-specific process-id of a JVM * @param mainClassName The main class - this is how we identify the right JVM. * You can pass in a fully-qualified name or just the classname. * E.g. com.sun.enterprise.glassfish.bootstrap.ASMain and ASMain work the same. * @return the process id if possible otherwise 0 */ static public List<Integer> getPid(String mainClassName) { if (mainClassName == null) return Collections.emptyList(); String plainName = plainClassName(mainClassName); Jps jps = new Jps(); List<Integer> ints = new LinkedList<Integer>(); Set<Map.Entry<Integer, String>> set = jps.pidMap.entrySet(); Iterator<Map.Entry<Integer, String>> it = set.iterator(); while (it.hasNext()) { Map.Entry<Integer, String> entry = it.next(); String valueFull = entry.getValue(); String valuePlain = plainClassName(valueFull); if (mainClassName.equals(valueFull) || plainName.equals(valuePlain)) // got a match! ints.add(entry.getKey()); } return ints; }
continue; if (!isJps(sublines[1])) { pidMap.put(aPid, sublines[1]);
/** * This is a bit tricky. "jps -l" will return a FQ classname * But it also might return a path if you start with "java -jar" * E.g. <pre> 2524 sun.tools.jps.Jps 5324 com.sun.enterprise.glassfish.bootstrap.ASMain 4120 D:\glassfish5\glassfish\bin\..\modules\admin-cli.jar </pre> * If there is a path -- then there is no classname and vice-versa * @param s * @return */ private static String plainClassName(String s) { if(s == null) return null; if(hasPath(s)) return stripPath(s); if (!s.contains(".") || s.endsWith(".")) return s; // we handled a/b/c/foo.jar // now let's handle foo.jar if(s.endsWith(".jar")) return s; return s.substring(s.lastIndexOf('.') + 1); }
/** * Kill the JVM with the given main classname. The classname can be * fully-qualified or just the classname (i.e. without the package name * prepended). * * @param pid * @return a String if the process was not killed for any reason including * if it does not exist. Return null if it was killed. */ public static String killJvm(String classname) { List<Integer> pids = Jps.getPid(classname); StringBuilder sb = new StringBuilder(); int numDead = 0; for (int p : pids) { String s = kill(p); if (s != null) sb.append(s).append('\n'); else ++numDead; } String err = sb.toString(); if (err.length() > 0 || numDead <= 0) return Strings.get("ProcessUtils.killjvmerror", err, numDead); return null; }
public static void main(String[] args) { Set<Map.Entry<Integer, String>> set = getProcessTable().entrySet(); System.out.println("** Got " + set.size() + " process entries"); for (Map.Entry<Integer, String> e : set) { System.out.printf("%d %s%n", e.getKey(), e.getValue()); } if(args.length > 0) { System.out.printf("Jps.isPid(%s) ==> %b%n", args[0], Jps.isPid(Integer.parseInt(args[0]))); } }
/** * Is the server still running? * This is only called when we're hanging around waiting for the server to die. * Byron Nevins, Nov 7, 2010 - Check to see if the process itself is still running * We use jps to check * If there are any problems fall back to the previous implementation of * isRunning() which looks for the pidfile to get deleted */ private boolean isRunningUsingJps() { int pp = getPrevPid(); if (pp < 0) return isRunningByCheckingForPidFile(); return Jps.isPid(pp); }
final static public Map<String, Integer> getProcessTable() { return new Jps().pidMap; }
continue; if (!isJps(sublines[1])) { pidMap.put(aPid, sublines[1]);
/** * Is the server still running? * This is only called when we're hanging around waiting for the server to die. * Byron Nevins, Nov 7, 2010 - Check to see if the process itself is still running * We use jps to check * If there are any problems fall back to the previous implementation of * isRunning() which looks for the pidfile to get deleted */ private final boolean isRunningUsingJps() { int pp = getPrevPid(); if (pp < 0) return isRunningByCheckingForPidFile(); return Jps.isPid(pp); }
static public Map<Integer, String> getProcessTable() { return new Jps().pidMap; }
/** * Is this pid owned by a process? * @param apid the pid of interest * @return whether there is a process running with that id */ final static public boolean isPid(int apid) { return new Jps().pidMap.containsKey(apid); }