org.zeroturnaround.process
Interface SystemProcess

All Known Implementing Classes:
AbstractProcess, AndProcess, CompositeProcess, Java8Process, JavaProcess, OrProcess, PidProcess, PollingProcess, SolarisProcess, UnixProcess, WindowsProcess

public interface SystemProcess

Represents a native system process.

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 or 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 is alive.

Some of the operations may be unsupported by throwing UnsupportedOperationException.

See Also:
Processes, ProcessUtil

Method Summary
 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 handled by this killer has terminated, or the specified waiting time elapses.
 

Method Detail

isAlive

boolean isAlive()
                throws IOException,
                       InterruptedException
Tests whether this process is alive.

This operation may also take some time to finish.

Returns:
true if this process is alive, false if it is finished or not found.
Throws:
IOException
InterruptedException

waitFor

void waitFor()
             throws InterruptedException
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

waitFor

boolean waitFor(long timeout,
                TimeUnit unit)
                throws InterruptedException
Causes the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified waiting time elapses.

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 itself may also take time. If the process has exited but timeout is reached before the checking operation finishes false is returned.

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the process has exited and false if the waiting time elapsed before the process has exited.
Throws:
InterruptedException

destroyGracefully

SystemProcess destroyGracefully()
                                throws IOException,
                                       InterruptedException,
                                       UnsupportedOperationException
Terminates this process. The process is gracefully terminated (like 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.

Returns:
this process object.
Throws:
UnsupportedOperationException - if this implementation cannot gracefully terminate any process.
IOException
InterruptedException

destroyForcefully

SystemProcess destroyForcefully()
                                throws IOException,
                                       InterruptedException,
                                       UnsupportedOperationException
Kills this process. The process is forcibly terminated (like 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.

Returns:
this process object.
Throws:
UnsupportedOperationException - if this implementation cannot forcibly terminate any process.
IOException
InterruptedException


Copyright © 2015 ZeroTurnaround. All rights reserved.