< prev index next >

jdk/src/java.base/share/classes/java/lang/ProcessHandle.java

Print this page




  72  * ProcessHandle provides no more access to, or control over, the native process
  73  * than would be allowed by a native application.
  74  *
  75  * @implSpec
  76  * In the case where ProcessHandles cannot be supported then the factory
  77  * methods must consistently throw {@link java.lang.UnsupportedOperationException}.
  78  * The methods of this class throw {@link java.lang.UnsupportedOperationException}
  79  * if the operating system does not allow access to query or kill a process.
  80  *
  81  * <p>
  82  * The {@code ProcessHandle} static factory methods return instances that are
  83  * <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>,
  84  * immutable and thread-safe.
  85  * Use of identity-sensitive operations (including reference equality
  86  * ({@code ==}), identity hash code, or synchronization) on these instances of
  87  * {@code ProcessHandle} may have unpredictable results and should be avoided.
  88  * Use {@link #equals(Object) equals} or
  89  * {@link #compareTo(ProcessHandle) compareTo} methods to compare ProcessHandles.
  90  *
  91  * @see Process
  92  * @since 1.9
  93  */
  94 public interface ProcessHandle extends Comparable<ProcessHandle> {
  95 
  96     /**
  97      * Returns the native process ID of the process. The native process ID is an
  98      * identification number that the operating system assigns to the process.
  99      * The operating system may reuse the process ID after a process terminates.
 100      * Use {@link #equals(Object) equals} or
 101      * {@link #compareTo(ProcessHandle) compareTo} to compare ProcessHandles.
 102      *
 103      * @return the native process ID of the process
 104      * @throws UnsupportedOperationException if the implementation
 105      *         does not support this operation
 106      */
 107     long getPid();
 108 
 109     /**
 110      * Returns an {@code Optional<ProcessHandle>} for an existing native process.
 111      *
 112      * @param pid a native process ID


 198         return ProcessHandleImpl.children(0);
 199     }
 200 
 201     /**
 202      * Returns a snapshot of information about the process.
 203      *
 204      * <p> A {@link ProcessHandle.Info} instance has accessor methods that return
 205      * information about the process if it is available.
 206      *
 207      * @return a snapshot of information about the process, always non-null
 208      */
 209     Info info();
 210 
 211     /**
 212      * Information snapshot about the process.
 213      * The attributes of a process vary by operating system and are not available
 214      * in all implementations.  Information about processes is limited
 215      * by the operating system privileges of the process making the request.
 216      * The return types are {@code Optional<T>} allowing explicit tests
 217      * and actions if the value is available.
 218      * @since 1.9
 219      */
 220     public interface Info {
 221         /**
 222          * Returns the executable pathname of the process.
 223          *
 224          * @return an {@code Optional<String>} of the executable pathname
 225          *         of the process
 226          */
 227         public Optional<String> command();
 228 
 229         /**
 230          * Returns the command line of the process.
 231          * <p>
 232          * If {@link #command command()} and  {@link #arguments arguments()} return
 233          * non-empty optionals, this is simply a convenience method which concatenates
 234          * the values of the two functions separated by spaces. Otherwise it will return a
 235          * best-effort, platform dependent representation of the command line.
 236          *
 237          * @apiNote Note that the returned executable pathname and the
 238          *          arguments may be truncated on some platforms due to system




  72  * ProcessHandle provides no more access to, or control over, the native process
  73  * than would be allowed by a native application.
  74  *
  75  * @implSpec
  76  * In the case where ProcessHandles cannot be supported then the factory
  77  * methods must consistently throw {@link java.lang.UnsupportedOperationException}.
  78  * The methods of this class throw {@link java.lang.UnsupportedOperationException}
  79  * if the operating system does not allow access to query or kill a process.
  80  *
  81  * <p>
  82  * The {@code ProcessHandle} static factory methods return instances that are
  83  * <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>,
  84  * immutable and thread-safe.
  85  * Use of identity-sensitive operations (including reference equality
  86  * ({@code ==}), identity hash code, or synchronization) on these instances of
  87  * {@code ProcessHandle} may have unpredictable results and should be avoided.
  88  * Use {@link #equals(Object) equals} or
  89  * {@link #compareTo(ProcessHandle) compareTo} methods to compare ProcessHandles.
  90  *
  91  * @see Process
  92  * @since 9
  93  */
  94 public interface ProcessHandle extends Comparable<ProcessHandle> {
  95 
  96     /**
  97      * Returns the native process ID of the process. The native process ID is an
  98      * identification number that the operating system assigns to the process.
  99      * The operating system may reuse the process ID after a process terminates.
 100      * Use {@link #equals(Object) equals} or
 101      * {@link #compareTo(ProcessHandle) compareTo} to compare ProcessHandles.
 102      *
 103      * @return the native process ID of the process
 104      * @throws UnsupportedOperationException if the implementation
 105      *         does not support this operation
 106      */
 107     long getPid();
 108 
 109     /**
 110      * Returns an {@code Optional<ProcessHandle>} for an existing native process.
 111      *
 112      * @param pid a native process ID


 198         return ProcessHandleImpl.children(0);
 199     }
 200 
 201     /**
 202      * Returns a snapshot of information about the process.
 203      *
 204      * <p> A {@link ProcessHandle.Info} instance has accessor methods that return
 205      * information about the process if it is available.
 206      *
 207      * @return a snapshot of information about the process, always non-null
 208      */
 209     Info info();
 210 
 211     /**
 212      * Information snapshot about the process.
 213      * The attributes of a process vary by operating system and are not available
 214      * in all implementations.  Information about processes is limited
 215      * by the operating system privileges of the process making the request.
 216      * The return types are {@code Optional<T>} allowing explicit tests
 217      * and actions if the value is available.
 218      * @since 9
 219      */
 220     public interface Info {
 221         /**
 222          * Returns the executable pathname of the process.
 223          *
 224          * @return an {@code Optional<String>} of the executable pathname
 225          *         of the process
 226          */
 227         public Optional<String> command();
 228 
 229         /**
 230          * Returns the command line of the process.
 231          * <p>
 232          * If {@link #command command()} and  {@link #arguments arguments()} return
 233          * non-empty optionals, this is simply a convenience method which concatenates
 234          * the values of the two functions separated by spaces. Otherwise it will return a
 235          * best-effort, platform dependent representation of the command line.
 236          *
 237          * @apiNote Note that the returned executable pathname and the
 238          *          arguments may be truncated on some platforms due to system


< prev index next >