public interface SystemProcess
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.
Processes,
ProcessUtil| Modifier and Type | Method and Description |
|---|---|
SystemProcess |
destroyForcefully()
Kills this process.
|
SystemProcess |
destroyGracefully()
Terminates this process.
|
boolean |
isAlive()
Tests whether this process is alive.
|
void |
waitFor()
Causes the current thread to wait, if necessary, until this process has terminated.
|
boolean |
waitFor(long timeout,
TimeUnit unit)
Causes the current thread to wait, if necessary, until the process has terminated, or the specified timeout is reached.
|
boolean isAlive()
throws IOException,
InterruptedException
This operation may take some time to finish.
true if this process is alive, false if it is finished or not found.IOException - on IO error.InterruptedException - if interrupted.void waitFor()
throws InterruptedException
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.
InterruptedException - if interrupted.boolean waitFor(long timeout,
TimeUnit unit)
throws InterruptedException
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 value false.
Checking the process status may take time.
If the process has exited but timeout is reached before the checking operation finishes, false is returned.
timeout - the maximum time to wait.unit - the time unit of the timeout argument.true if the process has exited and false if the timeout is reached before the process exited.InterruptedException - if interrupted.SystemProcess destroyGracefully() throws IOException, InterruptedException
kill -TERM does).
Note: The process may not terminate at all.
i.e. isAlive() may return true for any period after destroyGracefully() is called.
This method may be chained to waitFor() if needed.
If this process was already finished (or it was not found) this method finishes without throwing any errors.
UnsupportedOperationException - if this implementation is unable to gracefully terminate the process.IOException - on IO error.InterruptedException - if interrupted.SystemProcess destroyForcefully() throws IOException, InterruptedException
kill -KILL does).
Note: The process may not terminate immediately.
i.e. isAlive() may return true for a brief period after destroyForcefully() is called.
This method may be chained to waitFor() if needed.
If this process was already finished (or it was not found) this method finishes without throwing any errors.
UnsupportedOperationException - if this implementation is unable to forcibly terminate the process.IOException - on IO error.InterruptedException - if interrupted.Copyright © 2019 ZeroTurnaround. All rights reserved.