Public Member Functions | |
ProcessUtil (Logger logger) | |
List< String > | getJavaPIDs (Class<?> mainClass) throws IOException |
boolean | isJavaProcessRunning (Class<?> mainClass) throws IOException |
int | killProcess (String pid, boolean tough) throws IOException, InterruptedException |
void | setDebug (boolean DEBUG) |
Protected Member Functions | |
Map< String, List< String > > | getJavaPIDs () throws IOException |
Helper class to be used by tests which need to verify that some other process exists or does not exist, or that need to kill some process. Don't use this class in operational code!
alma.acs.testsupport.ProcessUtil.ProcessUtil | ( | Logger | logger | ) |
List<String> alma.acs.testsupport.ProcessUtil.getJavaPIDs | ( | Class<?> | mainClass | ) | throws IOException |
Gets the process IDs of all java processes run by the current user on the local host, whose main class is given as the parameter.
The "jps" command is used via Runtime.exec, which should work not only on Linux but also on Windows.
IOException |
References alma.acs.testsupport.ProcessUtil.getJavaPIDs().
Map<String, List<String> > alma.acs.testsupport.ProcessUtil.getJavaPIDs | ( | ) | throws IOException [protected] |
Gets a map with key=(running java main classes) and value=(list of the process IDs). Filters out sun.tools.jps.Jps which is the tool used to get the processes.
IOException | ||
InterruptedException |
References alma.acs.util.ProcessStreamGobbler.getStdout(), alma.acs.util.ProcessStreamGobbler.gobble(), alma.acs.util.ProcessStreamGobbler.hasStreamReadErrors(), and alma.acs.util.ProcessStreamGobbler.setDebug().
Referenced by alma.acs.testsupport.ProcessUtil.getJavaPIDs(), and alma.acs.testsupport.ProcessUtil.isJavaProcessRunning().
boolean alma.acs.testsupport.ProcessUtil.isJavaProcessRunning | ( | Class<?> | mainClass | ) | throws IOException |
Returns true if one or more JVMs are running the given Java main class on the local host as the current user.
IOException |
References alma.acs.testsupport.ProcessUtil.getJavaPIDs().
int alma.acs.testsupport.ProcessUtil.killProcess | ( | String | pid, | |
boolean | tough | |||
) | throws IOException, InterruptedException |
Kills a process with a given PID, which could be obtained from getJavaPIDs(Class).
Currently this method works only on Linux because it uses the "kill -9" command.
Currently the stdout and stderr from running "kill" are not gobbled because they are expected to be very small and thus won't block buffers etc. If they do, then use ProcessStreamGobbler also here.
tough | if true, a tough way of killing is used (kill -9) |
IOException | ||
InterruptedException |
void alma.acs.testsupport.ProcessUtil.setDebug | ( | boolean | DEBUG | ) |