Interface SystemProcess
- All Known Implementing Classes:
AbstractProcess,AndProcess,CompositeProcess,Java8Process,JavaProcess,OrProcess,PidProcess,PollingProcess,UnixProcess,WindowsProcess
This interface provides methods for checking aliveness, waiting for the process to complete and destroying (killing) the process. It does not have methods to control streams or check exit status of the process.
It is implementation specific whether the represented system process is a sub process of this JVM or some external process referred by a process ID, service name, etc. An instance of this class may also represent more than one process. In this case it is considered alive as long as any of the processes are alive.
Some of the operations may be unsupported by throwing UnsupportedOperationException.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionKills this process.Terminates this process.booleanisAlive()Tests whether this process is alive.voidwaitFor()Causes the current thread to wait, if necessary, until this process has terminated.booleanCauses the current thread to wait, if necessary, until the process has terminated, or the specified timeout is reached.
-
Method Details
-
isAlive
Tests whether this process is alive.This operation may take some time to finish.
- Returns:
trueif this process is alive,falseif it is finished or not found.- Throws:
IOException- on IO error.InterruptedException- if interrupted.
-
waitFor
Causes the current thread to wait, if necessary, until this process has terminated.This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.
- Throws:
InterruptedException- if interrupted.
-
waitFor
Causes the current thread to wait, if necessary, until the process has terminated, or the specified timeout is reached.If the process has already terminated then this method returns immediately with the value
true. If the process has not terminated and the timeout value is less than, or equal to, zero, then this method returns immediately with the valuefalse.Checking the process status may take time. If the process has exited but timeout is reached before the checking operation finishes,
falseis returned.- Parameters:
timeout- the maximum time to wait.unit- the time unit of the timeout argument.- Returns:
trueif the process has exited andfalseif the timeout is reached before the process exited.- Throws:
InterruptedException- if interrupted.
-
destroyGracefully
Terminates this process. The process is gracefully terminated (likekill -TERMdoes).Note: The process may not terminate at all. i.e.
isAlive()may returntruefor any period afterdestroyGracefully()is called. This method may be chained towaitFor()if needed.If this process was already finished (or it was not found) this method finishes without throwing any errors.
- Returns:
- this process object.
- Throws:
UnsupportedOperationException- if this implementation is unable to gracefully terminate the process.IOException- on IO error.InterruptedException- if interrupted.
-
destroyForcefully
Kills this process. The process is forcibly terminated (likekill -KILLdoes).Note: The process may not terminate immediately. i.e.
isAlive()may returntruefor a brief period afterdestroyForcefully()is called. This method may be chained towaitFor()if needed.If this process was already finished (or it was not found) this method finishes without throwing any errors.
- Returns:
- this process object.
- Throws:
UnsupportedOperationException- if this implementation is unable to forcibly terminate the process.IOException- on IO error.InterruptedException- if interrupted.
-