public final class ProcessHandleImpl extends Object implements ProcessHandle
ProcessHandle.Info| Modifier and Type | Method and Description |
|---|---|
Stream<ProcessHandle> |
children()
Returns a snapshot of the current direct children of the process.
|
int |
compareTo(ProcessHandle other)
Compares this ProcessHandle with the specified ProcessHandle for order.
|
static ProcessHandle |
current()
Returns a ProcessHandle for the current process.
|
Stream<ProcessHandle> |
descendants()
Returns a snapshot of the descendants of the process.
|
boolean |
destroy()
Requests the process to be killed.
|
boolean |
destroyForcibly()
Requests the process to be killed forcibly.
|
boolean |
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
int |
hashCode()
Returns an integer hash code for this object.
|
ProcessHandle.Info |
info()
Returns a snapshot of information about the process.
|
boolean |
isAlive()
Tests whether the process represented by this
ProcessHandle is alive. |
CompletableFuture<ProcessHandle> |
onExit()
Returns a
CompletableFuture<ProcessHandle> for the termination
of the process. |
Optional<ProcessHandle> |
parent()
Returns an
Optional<ProcessHandle> for the parent process. |
long |
pid()
Returns the native process ID of the process.
|
boolean |
supportsNormalTermination()
Returns
true if the implementation of ProcessHandle.destroy()
normally terminates the process. |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitallProcesses, ofpublic static ProcessHandle current()
ProcessHandleSystem.exit instead.current in interface ProcessHandlepublic long pid()
ProcessHandleequals or
compareTo to compare ProcessHandles.pid in interface ProcessHandlepublic Optional<ProcessHandle> parent()
ProcessHandleOptional<ProcessHandle> for the parent process.
Note that Processes in a zombie state usually don't have a parent.parent in interface ProcessHandleOptional<ProcessHandle> of the parent process;
the Optional is empty if the child process does not have a parent
or if the parent is not available, possibly due to operating system limitationspublic Stream<ProcessHandle> children()
ProcessHandleProcessHandle.parent() of a direct child process is the process.
Typically, a process that is not alive has no children.
Note that processes are created and terminate asynchronously.
There is no guarantee that a process is alive.
children in interface ProcessHandlepublic Stream<ProcessHandle> descendants()
ProcessHandlenot alive has no children.
Note that processes are created and terminate asynchronously.
There is no guarantee that a process is alive.
descendants in interface ProcessHandlepublic ProcessHandle.Info info()
ProcessHandle A ProcessHandle.Info instance has accessor methods that return
information about the process if it is available.
info in interface ProcessHandlepublic CompletableFuture<ProcessHandle> onExit()
ProcessHandleCompletableFuture<ProcessHandle> for the termination
of the process.
The CompletableFuture provides the ability
to trigger dependent functions or actions that may be run synchronously
or asynchronously upon process termination.
When the process has terminated the CompletableFuture is
completed regardless
of the exit status of the process.
The onExit method can be called multiple times to invoke
independent actions when the process exits.
Calling onExit().get() waits for the process to terminate and returns
the ProcessHandle. The future can be used to check if the process is
done or to
wait for it to terminate.
Cancelling
the CompleteableFuture does not affect the Process.
onExit in interface ProcessHandleCompletableFuture<ProcessHandle> for the ProcessHandlepublic boolean supportsNormalTermination()
ProcessHandletrue if the implementation of ProcessHandle.destroy()
normally terminates the process.
Returns false if the implementation of destroy
forcibly and immediately terminates the process.supportsNormalTermination in interface ProcessHandletrue if the implementation of ProcessHandle.destroy()
normally terminates the process;
otherwise, ProcessHandle.destroy() forcibly terminates the processpublic boolean destroy()
ProcessHandleProcessHandle object is
normally terminated or not is
implementation dependent.
Forcible process destruction is defined as the immediate termination of the
process, whereas normal termination allows the process to shut down cleanly.
If the process is not alive, no action is taken.
The operating system access controls may prevent the process
from being killed.
The CompletableFuture from ProcessHandle.onExit() is
completed
when the process has terminated.
Note: The process may not terminate immediately.
For example, isAlive() may return true for a brief period
after destroy() is called.
destroy in interface ProcessHandletrue if termination was successfully requested,
otherwise falsepublic boolean destroyForcibly()
ProcessHandleProcessHandle object is
forcibly terminated.
Forcible process destruction is defined as the immediate termination of the
process, whereas normal termination allows the process to shut down cleanly.
If the process is not alive, no action is taken.
The operating system access controls may prevent the process
from being killed.
The CompletableFuture from ProcessHandle.onExit() is
completed
when the process has terminated.
Note: The process may not terminate immediately.
For example, isAlive() may return true for a brief period
after destroyForcibly() is called.
destroyForcibly in interface ProcessHandletrue if termination was successfully requested,
otherwise falsepublic boolean isAlive()
ProcessHandleProcessHandle is alive.
Process termination is implementation and operating system specific.
The process is considered alive as long as the PID is valid.isAlive in interface ProcessHandletrue if the process represented by this
ProcessHandle object has not yet terminatedpublic int compareTo(ProcessHandle other)
ProcessHandleObject.equals(java.lang.Object),
which returns true if and only if two instances of ProcessHandle
are of the same implementation and represent the same system process.
Comparison is only supported among objects of same implementation.
If attempt is made to mutually compare two different implementations
of ProcessHandles, ClassCastException is thrown.compareTo in interface Comparable<ProcessHandle>compareTo in interface ProcessHandleother - the ProcessHandle to be comparedpublic String toString()
ObjectgetClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString method
if you intend implementing your own toString method.
public int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in interface ProcessHandlehashCode in class ObjectObject.equals(java.lang.Object)public boolean equals(Object o)
Objecto must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true only if this ==
o. See Writing a correct
equals method
if you intend implementing your own equals method.
The general contract for the equals and Object.hashCode() methods is that if equals returns true for
any two objects, then hashCode() must return the same value for
these objects. This means that subclasses of Object usually
override either both methods or neither of them.
equals in interface ProcessHandleequals in class Objecto - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()