Class ProcessUtils
java.lang.Object
com.sun.enterprise.universal.process.ProcessUtils
Includes a somewhat kludgy way to get the pid for "me". Another casualty of
the JDK catering to the LEAST common denominator. Some obscure OS might not
have a pid! The name returned from the JMX method is like so: 12345
- Author:
- bnevins, David Matejcek
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileLook for name in the Path.static booleanisAlive(long pid) static booleanstatic booleanisListening(HostAndPort endpoint) static voidKill the process with the given Process ID and wait until it's gone - that means that the watchedPidFile is deleted OR the process is not resolved as alive by theProcessHandle.isAlive()OR we cannot retrieve the command line of the process viaProcessHandle.Info.commandLine().static longstatic voidsaveCurrentPid(File pidFile) Saves current pid file to the file.static boolean
-
Method Details
-
getExe
Look for name in the Path. If it is found and if it is executable then return a File object pointing to it. Otherwise return nu- Parameters:
name- the name of the file with no path- Returns:
- the File object or null
-
saveCurrentPid
Saves current pid file to the file.- Parameters:
pidFile-- Throws:
IOException
-
isAlive
- Parameters:
pidFile-- Returns:
- true if the pid file exists and the process with the pid inside is alive.
-
isAlive
public static boolean isAlive(long pid) -
loadPid
- Parameters:
pidFile- existing file containing pid.- Returns:
- pid from the file
- Throws:
IllegalArgumentException- non-existing, empty or unparseable file
-
isListening
- Parameters:
endpoint- endpoint host and port to use.- Returns:
- true if the endpoint is listening on socket
-
kill
public static void kill(File pidFile, File watchedPidFile, Duration timeout, boolean printDots) throws KillNotPossibleException, KillTimeoutException Kill the process with the given Process ID and wait until it's gone - that means that the watchedPidFile is deleted OR the process is not resolved as alive by theProcessHandle.isAlive()OR we cannot retrieve the command line of the process viaProcessHandle.Info.commandLine().- Parameters:
pidFile- - used to load pidwatchedPidFile- - if this file vanish, we expect that the process stopped.timeout- - timeout to wait until to meet conditions meaning that the process stoppedprintDots- - print one dot per second when waiting.- Throws:
KillNotPossibleException- It wasn't possible to send the kill signal to the process.KillTimeoutException- Signal was sent, but process is still alive after the timeout.
-
waitFor
- Parameters:
sign- logic defining what we are waiting for.timeout-printDots- print dot each second and new line in the end.- Returns:
- true if the sign returned true before timeout.
-