jdk/src/java.base/share/classes/java/lang/ProcessHandle.java
author thartmann
Tue, 03 Nov 2015 09:42:11 +0100
changeset 33663 2cd62a4bd471
parent 32764 1586fc6697da
child 33648 9564031a20e0
permissions -rw-r--r--
8141132: JEP 254: Compact Strings Summary: Adopt a more space-efficient internal representation for strings. Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti Contributed-by: Brent Christian <brent.christian@oracle.com>, Vivek Deshpande <vivek.r.deshpande@intel.com>, Tobias Hartmann <tobias.hartmann@oracle.com>, Charlie Hunt <charlie.hunt@oracle.com>, Vladimir Kozlov <vladimir.kozlov@oracle.com>, Roger Riggs <roger.riggs@oracle.com>, Xueming Shen <xueming.shen@oracle.com>, Aleksey Shipilev <aleksey.shipilev@oracle.com>, Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     1
/*
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     4
 *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    10
 *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    15
 * accompanied this code).
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    16
 *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    20
 *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    23
 * questions.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    24
 */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    25
package java.lang;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    26
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    27
import java.time.Duration;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    28
import java.time.Instant;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    29
import java.util.Optional;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    30
import java.util.concurrent.CompletableFuture;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    31
import java.util.stream.Stream;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    32
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    33
/**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    34
 * ProcessHandle identifies and provides control of native processes. Each
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    35
 * individual process can be monitored for liveness, list its children,
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    36
 * get information about the process or destroy it.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    37
 * By comparison, {@link java.lang.Process Process} instances were started
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    38
 * by the current process and additionally provide access to the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    39
 * input, output, and error streams.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    40
 * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    41
 * The native process ID is an identification number that the
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    42
 * operating system assigns to the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    43
 * The range for process id values is dependent on the operating system.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    44
 * For example, an embedded system might use a 16-bit value.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    45
 * Status information about a process is retrieved from the native system
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    46
 * and may change asynchronously; processes may be created or terminate
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    47
 * spontaneously.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    48
 * The time between when a process terminates and the process id
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    49
 * is reused for a new process is unpredictable.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    50
 * Race conditions can exist between checking the status of a process and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    51
 * acting upon it. When using ProcessHandles avoid assumptions
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    52
 * about the liveness or identity of the underlying process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    53
 * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    54
 * Each ProcessHandle identifies and allows control of a process in the native
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    55
 * system. ProcessHandles are returned from the factory methods {@link #current()},
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    56
 * {@link #of(long)},
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    57
 * {@link #children}, {@link #allChildren}, {@link #parent()} and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    58
 * {@link #allProcesses()}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    59
 * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    60
 * The {@link Process} instances created by {@link ProcessBuilder} can be queried
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    61
 * for a ProcessHandle that provides information about the Process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    62
 * ProcessHandle references should not be freely distributed.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    63
 *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    64
 * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    65
 * A {@link java.util.concurrent.CompletableFuture} available from {@link #onExit}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    66
 * can be used to wait for process termination, and possibly trigger dependent
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    67
 * actions.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    68
 * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    69
 * The factory methods limit access to ProcessHandles using the
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    70
 * SecurityManager checking the {@link RuntimePermission RuntimePermission("manageProcess")}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    71
 * The ability to control processes is also restricted by the native system,
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    72
 * ProcessHandle provides no more access to, or control over, the native process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    73
 * than would be allowed by a native application.
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 30899
diff changeset
    74
 *
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    75
 * @implSpec
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    76
 * In the case where ProcessHandles cannot be supported then the factory
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    77
 * methods must consistently throw {@link java.lang.UnsupportedOperationException}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    78
 * The methods of this class throw {@link java.lang.UnsupportedOperationException}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    79
 * if the operating system does not allow access to query or kill a process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    80
 *
31681
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    81
 * <p>
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    82
 * The {@code ProcessHandle} static factory methods return instances that are
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    83
 * <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>,
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    84
 * immutable and thread-safe.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    85
 * Use of identity-sensitive operations (including reference equality
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    86
 * ({@code ==}), identity hash code, or synchronization) on these instances of
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    87
 * {@code ProcessHandle} may have unpredictable results and should be avoided.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    88
 * Use {@link #equals(Object) equals} or
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    89
 * {@link #compareTo(ProcessHandle) compareTo} methods to compare ProcessHandles.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    90
 *
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    91
 * @see Process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    92
 * @since 1.9
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    93
 */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    94
public interface ProcessHandle extends Comparable<ProcessHandle> {
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    95
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    96
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    97
     * Returns the native process ID of the process. The native process ID is an
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
    98
     * identification number that the operating system assigns to the process.
31681
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
    99
     * The operating system may reuse the process ID after a process terminates.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   100
     * Use {@link #equals(Object) equals} or
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   101
     * {@link #compareTo(ProcessHandle) compareTo} to compare ProcessHandles.
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   102
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   103
     * @return the native process ID of the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   104
     * @throws UnsupportedOperationException if the implementation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   105
     *         does not support this operation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   106
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   107
    long getPid();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   108
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   109
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   110
     * Returns an {@code Optional<ProcessHandle>} for an existing native process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   111
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   112
     * @param pid a native process ID
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   113
     * @return an {@code Optional<ProcessHandle>} of the PID for the process;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   114
     *         the {@code Optional} is empty if the process does not exist
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   115
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   116
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   117
     * @throws UnsupportedOperationException if the implementation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   118
     *         does not support this operation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   119
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   120
    public static Optional<ProcessHandle> of(long pid) {
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   121
        return ProcessHandleImpl.get(pid);
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   122
    }
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   123
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   124
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   125
     * Returns a ProcessHandle for the current process. The ProcessHandle cannot be
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   126
     * used to destroy the current process, use {@link System#exit System.exit} instead.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   127
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   128
     * @return a ProcessHandle for the current process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   129
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   130
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   131
     * @throws UnsupportedOperationException if the implementation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   132
     *         does not support this operation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   133
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   134
    public static ProcessHandle current() {
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   135
        return ProcessHandleImpl.current();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   136
    }
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   137
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   138
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   139
     * Returns an {@code Optional<ProcessHandle>} for the parent process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   140
     * Note that Processes in a zombie state usually don't have a parent.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   141
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   142
     * @return an {@code Optional<ProcessHandle>} of the parent process;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   143
     *         the {@code Optional} is empty if the child process does not have a parent
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   144
     *         or if the parent is not available, possibly due to operating system limitations
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   145
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   146
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   147
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   148
    Optional<ProcessHandle> parent();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   149
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   150
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   151
     * Returns a snapshot of the current direct children of the process.
32764
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   152
     * The {@link #parent} of a direct child process is the process.
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   153
     * Typically, a process that is {@link #isAlive not alive} has no children.
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   154
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   155
     * <em>Note that processes are created and terminate asynchronously.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   156
     * There is no guarantee that a process is {@link #isAlive alive}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   157
     * </em>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   158
     *
32764
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   159
     * @return a sequential Stream of ProcessHandles for processes that are
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   160
     *         direct children of the process
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   161
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   162
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   163
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   164
    Stream<ProcessHandle> children();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   165
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   166
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   167
     * Returns a snapshot of the current direct and indirect children of the process.
32764
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   168
     * An indirect child is one whose parent is either a direct child or
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   169
     * another indirect child.
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   170
     * Typically, a process that is {@link #isAlive not alive} has no children.
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   171
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   172
     * <em>Note that processes are created and terminate asynchronously.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   173
     * There is no guarantee that a process is {@link #isAlive alive}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   174
     * </em>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   175
     *
32764
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   176
     * @return a sequential Stream of ProcessHandles for processes that are
1586fc6697da 8132883: The spec of allChildren/children of j.l.Process/ProcessHandle need to be relaxed
rriggs
parents: 32209
diff changeset
   177
     *         direct and indirect children of the process
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   178
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   179
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   180
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   181
    Stream<ProcessHandle> allChildren();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   182
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   183
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   184
     * Returns a snapshot of all processes visible to the current process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   185
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   186
     * <em>Note that processes are created and terminate asynchronously. There
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   187
     * is no guarantee that a process in the stream is alive or that no other
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   188
     * processes may have been created since the inception of the snapshot.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   189
     * </em>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   190
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   191
     * @return a Stream of ProcessHandles for all processes
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   192
     * @throws SecurityException if a security manager has been installed and
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   193
     *         it denies RuntimePermission("manageProcess")
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   194
     * @throws UnsupportedOperationException if the implementation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   195
     *         does not support this operation
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   196
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   197
    static Stream<ProcessHandle> allProcesses() {
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   198
        return ProcessHandleImpl.children(0);
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   199
    }
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   200
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   201
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   202
     * Returns a snapshot of information about the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   203
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   204
     * <p> An {@code Info} instance has various accessor methods that return
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   205
     * information about the process, if the process is alive and the
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   206
     * information is available.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   207
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   208
     * @return a snapshot of information about the process, always non-null
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   209
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   210
    Info info();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   211
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   212
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   213
     * Information snapshot about the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   214
     * The attributes of a process vary by operating system and are not available
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   215
     * in all implementations.  Information about processes is limited
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   216
     * by the operating system privileges of the process making the request.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   217
     * The return types are {@code Optional<T>} allowing explicit tests
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   218
     * and actions if the value is available.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   219
     * @since 1.9
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   220
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   221
    public interface Info {
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   222
        /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   223
         * Returns the executable pathname of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   224
         *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   225
         * @return an {@code Optional<String>} of the executable pathname
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   226
         *         of the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   227
         */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   228
        public Optional<String> command();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   229
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   230
        /**
32209
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   231
         * Returns the command line of the process.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   232
         * <p>
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   233
         * If {@link #command command()} and  {@link #arguments arguments()} return
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   234
         * non-empty optionals, this is simply a convenience method which concatenates
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   235
         * the values of the two functions separated by spaces. Otherwise it will return a
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   236
         * best-effort, platform dependent representation of the command line.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   237
         *
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   238
         * @apiNote Note that the returned executable pathname and the
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   239
         *          arguments may be truncated on some platforms due to system
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   240
         *          limitations.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   241
         *          <p>
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   242
         *          The executable pathname may contain only the
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   243
         *          name of the executable without the full path information.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   244
         *          It is undecideable whether white space separates different
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   245
         *          arguments or is part of a single argument.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   246
         *
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   247
         * @return an {@code Optional<String>} of the command line
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   248
         *         of the process
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   249
         */
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   250
        public Optional<String> commandLine();
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   251
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   252
        /**
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   253
         * Returns an array of Strings of the arguments of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   254
         *
32209
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   255
         * @apiNote On some platforms, native applications are free to change
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   256
         *          the arguments array after startup and this method may only
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   257
         *          show the changed values.
24bb680a1609 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
simonis
parents: 31681
diff changeset
   258
         *
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   259
         * @return an {@code Optional<String[]>} of the arguments of the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   260
         */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   261
        public Optional<String[]> arguments();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   262
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   263
        /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   264
         * Returns the start time of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   265
         *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   266
         * @return an {@code Optional<Instant>} of the start time of the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   267
         */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   268
        public Optional<Instant> startInstant();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   269
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   270
        /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   271
         * Returns the total cputime accumulated of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   272
         *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   273
         * @return an {@code Optional<Duration>} for the accumulated total cputime
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   274
         */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   275
        public Optional<Duration> totalCpuDuration();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   276
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   277
        /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   278
         * Return the user of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   279
         *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   280
         * @return an {@code Optional<String>} for the user of the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   281
         */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   282
        public Optional<String> user();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   283
    }
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   284
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   285
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   286
     * Returns a {@code CompletableFuture<ProcessHandle>} for the termination
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   287
     * of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   288
     * The {@link java.util.concurrent.CompletableFuture} provides the ability
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   289
     * to trigger dependent functions or actions that may be run synchronously
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   290
     * or asynchronously upon process termination.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   291
     * When the process terminates the CompletableFuture is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   292
     * {@link java.util.concurrent.CompletableFuture#complete completed} regardless
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   293
     * of the exit status of the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   294
     * The {@code onExit} method can be called multiple times to invoke
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   295
     * independent actions when the process exits.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   296
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   297
     * Calling {@code onExit().get()} waits for the process to terminate and returns
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   298
     * the ProcessHandle. The future can be used to check if the process is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   299
     * {@link java.util.concurrent.CompletableFuture#isDone done} or to
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   300
     * {@link java.util.concurrent.Future#get() wait} for it to terminate.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   301
     * {@link java.util.concurrent.Future#cancel(boolean) Cancelling}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   302
     * the CompleteableFuture does not affect the Process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   303
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   304
     * If the process is {@link #isAlive not alive} the {@link CompletableFuture}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   305
     * returned has been {@link java.util.concurrent.CompletableFuture#complete completed}.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   306
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   307
     * @return a new {@code CompletableFuture<ProcessHandle>} for the ProcessHandle
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   308
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   309
     * @throws IllegalStateException if the process is the current process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   310
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   311
    CompletableFuture<ProcessHandle> onExit();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   312
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   313
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   314
     * Returns {@code true} if the implementation of {@link #destroy}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   315
     * normally terminates the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   316
     * Returns {@code false} if the implementation of {@code destroy}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   317
     * forcibly and immediately terminates the process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   318
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   319
     * @return {@code true} if the implementation of {@link #destroy}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   320
     *         normally terminates the process;
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   321
     *         otherwise, {@link #destroy} forcibly terminates the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   322
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   323
    boolean supportsNormalTermination();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   324
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   325
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   326
     * Requests the process to be killed.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   327
     * Whether the process represented by this {@code ProcessHandle} object is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   328
     * {@link #supportsNormalTermination normally terminated} or not is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   329
     * implementation dependent.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   330
     * Forcible process destruction is defined as the immediate termination of the
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   331
     * process, whereas normal termination allows the process to shut down cleanly.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   332
     * If the process is not alive, no action is taken.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   333
     * The operating system access controls may prevent the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   334
     * from being killed.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   335
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   336
     * The {@link java.util.concurrent.CompletableFuture} from {@link #onExit} is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   337
     * {@link java.util.concurrent.CompletableFuture#complete completed}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   338
     * when the process has terminated.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   339
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   340
     * Note: The process may not terminate immediately.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   341
     * For example, {@code isAlive()} may return true for a brief period
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   342
     * after {@code destroy()} is called.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   343
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   344
     * @return {@code true} if termination was successfully requested,
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   345
     *         otherwise {@code false}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   346
     * @throws IllegalStateException if the process is the current process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   347
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   348
    boolean destroy();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   349
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   350
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   351
     * Requests the process to be killed forcibly.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   352
     * The process represented by this {@code ProcessHandle} object is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   353
     * forcibly terminated.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   354
     * Forcible process destruction is defined as the immediate termination of the
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   355
     * process, whereas normal termination allows the process to shut down cleanly.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   356
     * If the process is not alive, no action is taken.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   357
     * The operating system access controls may prevent the process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   358
     * from being killed.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   359
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   360
     * The {@link java.util.concurrent.CompletableFuture} from {@link #onExit} is
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   361
     * {@link java.util.concurrent.CompletableFuture#complete completed}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   362
     * when the process has terminated.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   363
     * <p>
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   364
     * Note: The process may not terminate immediately.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   365
     * For example, {@code isAlive()} may return true for a brief period
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   366
     * after {@code destroyForcibly()} is called.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   367
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   368
     * @return {@code true} if termination was successfully requested,
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   369
     *         otherwise {@code false}
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   370
     * @throws IllegalStateException if the process is the current process
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   371
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   372
    boolean destroyForcibly();
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   373
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   374
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   375
     * Tests whether the process represented by this {@code ProcessHandle} is alive.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   376
     * Process termination is implementation and operating system specific.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   377
     * The process is considered alive as long as the PID is valid.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   378
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   379
     * @return {@code true} if the process represented by this
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   380
     *         {@code ProcessHandle} object has not yet terminated
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   381
     */
31681
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   382
    boolean isAlive();
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   383
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   384
    /**
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   385
     * Returns a hash code value for this ProcessHandle.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   386
     * The hashcode value follows the general contract for {@link Object#hashCode()}.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   387
     * The value is a function of the {@link #getPid getPid()} value and
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   388
     * may be a function of additional information to uniquely identify the process.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   389
     * If two ProcessHandles are equal according to the {@link #equals(Object) equals}
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   390
     * method, then calling the hashCode method on each of the two objects
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   391
     * must produce the same integer result.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   392
     *
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   393
     * @return a hash code value for this object
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   394
     */
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   395
    @Override
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   396
    int hashCode();
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   397
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   398
    /**
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   399
     * Returns {@code true} if {@code other} object is non-null, is of the
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   400
     * same implementation, and represents the same system process;
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   401
     * otherwise it returns {@code false}.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   402
     * @implNote
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   403
     * It is implementation specific whether ProcessHandles with the same PID
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   404
     * represent the same system process. ProcessHandle implementations
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   405
     * should contain additional information to uniquely identify the process.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   406
     * For example, the start time of the process could be used
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   407
     * to determine if the PID has been re-used.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   408
     * The implementation of {@code equals} should return {@code true} for two
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   409
     * ProcessHandles with the same PID unless there is information to
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   410
     * distinguish them.
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   411
     *
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   412
     * @param other another object
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   413
     * @return {@code true} if the {@code other} object is non-null,
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   414
     *         is of the same implementation class and represents
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   415
     *         the same system process; otherwise returns {@code false}
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   416
     */
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   417
    @Override
e9a9d5b369bc 8129344: (process) ProcessHandle instances should define equals and be value-based
rriggs
parents: 31061
diff changeset
   418
    boolean equals(Object other);
30899
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   419
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   420
    /**
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   421
     * Compares this ProcessHandle with the specified ProcessHandle for order.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   422
     * The order is not specified, but is consistent with {@link Object#equals},
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   423
     * which returns {@code true} if and only if two instances of ProcessHandle
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   424
     * are of the same implementation and represent the same system process.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   425
     * Comparison is only supported among objects of same implementation.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   426
     * If attempt is made to mutually compare two different implementations
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   427
     * of {@link ProcessHandle}s, {@link ClassCastException} is thrown.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   428
     *
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   429
     * @param other the ProcessHandle to be compared
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   430
     * @return a negative integer, zero, or a positive integer as this object
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   431
     * is less than, equal to, or greater than the specified object.
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   432
     * @throws NullPointerException if the specified object is null
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   433
     * @throws ClassCastException if the specified object is not of same class
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   434
     *         as this object
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   435
     */
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   436
    @Override
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   437
    int compareTo(ProcessHandle other);
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   438
d2408e757489 8077350: JEP 102 Process API Updates Implementation
rriggs
parents:
diff changeset
   439
}