add core method to query multiple pids matching a query

This commit is contained in:
adam-m 2013-03-28 09:47:16 -04:00
parent 6f8e8a0e10
commit bb770ea958

View File

@ -416,14 +416,15 @@ public class PlatformUtil {
return pid; return pid;
} }
/** /**
* Query and get PID of another java process * Query and get PID of another java process
* *
* @sigarSubQuery a sigar subquery to identify a unique java process among other java processes, * @sigarSubQuery a sigar subquery to identify a unique java process among
* for example, by class name, use: Args.*.eq=org.jboss.Main * other java processes, for example, by class name, use:
* more examples here: http://support.hyperic.com/display/SIGAR/PTQL * Args.*.eq=org.jboss.Main more examples here:
* * http://support.hyperic.com/display/SIGAR/PTQL
*
* @return PID of a java process or -1 if it couldn't be determined * @return PID of a java process or -1 if it couldn't be determined
*/ */
public static synchronized long getJavaPID(String sigarSubQuery) { public static synchronized long getJavaPID(String sigarSubQuery) {
@ -445,7 +446,37 @@ public class PlatformUtil {
return jpid; return jpid;
} }
/**
* Query and get PIDs of another java processes matching a query
*
* @sigarSubQuery a sigar subquery to identify a java processes among other
* java processes, for example, by class name, use: Args.*.eq=org.jboss.Main
* more examples here: http://support.hyperic.com/display/SIGAR/PTQL
*
* @return array of PIDs of a java processes matching the query or null if
* it couldn't be determined
*/
public static synchronized long[] getJavaPIDs(String sigarSubQuery) {
long[] jpids = null;
final String sigarQuery = "State.Name.sw=java," + sigarSubQuery;
try {
if (sigar == null) {
sigar = org.sleuthkit.autopsy.corelibs.SigarLoader.getSigar();
}
if (sigar != null) {
ProcessFinder finder = new ProcessFinder(sigar);
jpids = finder.find(sigarQuery);
} else {
System.out.println("Can't get PIDs of a java process, sigar not initialized");
}
} catch (Exception e) {
System.out.println("Can't get PIDs for query: " + sigarQuery + ", " + e.toString());
}
return jpids;
}
/** /**
* Kill a process by PID by sending signal to it using Sigar * Kill a process by PID by sending signal to it using Sigar
* *
@ -467,7 +498,6 @@ public class PlatformUtil {
} }
/** /**
* Query and return virtual memory used by the process * Query and return virtual memory used by the process
* *
@ -527,8 +557,8 @@ public class PlatformUtil {
+ Long.toString(maxMemory) + ", " + Long.toString(totalMemory) + Long.toString(maxMemory) + ", " + Long.toString(totalMemory)
+ ", " + Long.toString(freeMemory); + ", " + Long.toString(freeMemory);
} }
/** /**
* Return formatted string with all memory usage (jvm, physical, native) * Return formatted string with all memory usage (jvm, physical, native)
* *
* @return formatted string with all memory usage info * @return formatted string with all memory usage info