Details

    • Author:
      Alan Bateman
    • JEP Type:
      Feature
    • Exposure:
      Open
    • Subcomponent:
    • Scope:
      SE
    • Discussion:
      core dash libs dash dev at openjdk dot java dot net
    • Effort:
      M
    • Duration:
      M
    • Alert Status:
       Green
    • JEP Number:
      102

      Description

      Summary

      Improve the API for controlling and managing operating-system processes.

      Motivation

      The limitations of the current API often force developers to resort to native code.

      Description

      Java SE provides limited support for native operating-system processes. It provides a basic API to setup the environment and start a process. The process streams can, since Java SE 7, be redirected to files, pipes, or can be inherited. Once started, the API can be used to destroy the process and/or wait for the process to terminate.

      The java.lang.Process class is enhanced to provide the operating specific process id of the process, information about the process including the arguments, the command, the start time of the process, the accumulated cpu time of the process and the user name for the process.

      The java.lang.ProcessHandle class returns information about each process as provided by the operating system including process id, arguments, command, start time, etc. A ProcessHandle can return the process' parent, and the direct children, and to all descendants via a stream of ProcessHandles.

      ProcessHandles can be used to destroy processes and monitor process liveness. With ProcessHandle.onExit, the asynchronous mechanisms of CompletableFuture can be used to schedule an action to be taken when the process exits.

      Access to information about processes and control of processes is subject to security manager permissions and are limited by the normal operating system access controls.

      Testing

      The classes or methods introduced will require new unit tests that can be developed along with the implementation. More functional tests would be useful too.

      Risks and Assumptions

      The main risk with this API is differences between operating systems, in particular Windows.

      The design of this API needs to accommodate possible deployment on smaller devices with different operating system models. It should also take into account environments where multiple Java virtual machines are running in the same operating system process. These considerations could lead to a more abstract API and/or increase the design effort.

        Issue Links

          Activity

          Hide
          rriggs Roger Riggs added a comment -
          With respect to the JEP 102 bullet:
             "The ability to enumerate Java virtual machines and processes on the system. Information on each process may include its pid, name, state, and maybe resource usage."

            The capability is not planned to be specialized for Java Virtual Machines; information common to any process would be made available.
            VM specific functions are already provided by serviceability in the commands jps, jcmd, etc.
          Show
          rriggs Roger Riggs added a comment - With respect to the JEP 102 bullet:    "The ability to enumerate Java virtual machines and processes on the system. Information on each process may include its pid, name, state, and maybe resource usage."   The capability is not planned to be specialized for Java Virtual Machines; information common to any process would be made available.   VM specific functions are already provided by serviceability in the commands jps, jcmd, etc.
          Hide
          rriggs Roger Riggs added a comment -
          A feature missing from the api to query processes is information about the processes that is available from the OS.
          For example, cpu time, start time, user id, group id, command, arguments, working directory, memory size.
          The information would be provided on an as available basis with a set of known keys,
          but not every OS would be required to return all the information.
          Show
          rriggs Roger Riggs added a comment - A feature missing from the api to query processes is information about the processes that is available from the OS. For example, cpu time, start time, user id, group id, command, arguments, working directory, memory size. The information would be provided on an as available basis with a set of known keys, but not every OS would be required to return all the information.
          Hide
          alanb Alan Bateman added a comment -
          Just to add that the API proposed here are expected to be added to Java SE and so would need be present in all Java SE implementations. There is separate spec clarification in progress to make it clearer that support for creating operating system will be optional (to allow for environments such as iOS). That may be what Aleksey's question is about.
          Show
          alanb Alan Bateman added a comment - Just to add that the API proposed here are expected to be added to Java SE and so would need be present in all Java SE implementations. There is separate spec clarification in progress to make it clearer that support for creating operating system will be optional (to allow for environments such as iOS). That may be what Aleksey's question is about.
          Hide
          bobv Bob Vandette added a comment -
          Yes. Whatever new support is added in this area, please make sure that the specification allows it to be optional.
          There's an approved CCC request that clarifies the optionality of the existing process execution APIs for JDK 9.

          http://ccc.us.oracle.com/8055330
          Show
          bobv Bob Vandette added a comment - Yes. Whatever new support is added in this area, please make sure that the specification allows it to be optional. There's an approved CCC request that clarifies the optionality of the existing process execution APIs for JDK 9. http://ccc.us.oracle.com/8055330
          Hide
          rriggs Roger Riggs added a comment -
          The main body of the ProcessHandle implementation has been pushed in JDK-8077350 JEP 102 Process API Updates Implementation.
          There is some remaining work and some incrementally suggested enhancements.
          Show
          rriggs Roger Riggs added a comment - The main body of the ProcessHandle implementation has been pushed in JDK-8077350 JEP 102 Process API Updates Implementation. There is some remaining work and some incrementally suggested enhancements.

            People

            • Assignee:
              rriggs Roger Riggs
              Reporter:
              alanb Alan Bateman
              Owner:
              Roger Riggs
              Endorsed By:
              Brian Goetz
            • Votes:
              0 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Integration Due: