Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8176272

(process) ProcessHandle::onExit fails to wait for non-child process

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b162
    • OS:
      linux

      Backports

        Description

        I was trying to get an example to work with the new ProcessHandle API. My goal was to wait on another process (Spotify) to terminate before printing something to the console:

        ProcessHandle handle =
               ProcessHandle.allProcesses()
                 .filter(h -> h.info().commandLine().map(cmd -> cmd.contains("Spotify")).orElse(false))
               .findFirst()
               .orElseThrow(() -> new IllegalArgumentException("No matching handle found"));

        System.out.println(handle.info());

        ProcessHandle completed = handle.onExit().get();
        System.out.println(completed.isAlive());

        However this code doesn't wait on `handle` to be terminated, as the JavaDoc of onExit led me to believe: "Calling onExit().get() waits for the process to terminate and returns the ProcessHandle.". What I expected: the get() call blocks until I terminate the Spotify process. Instead, it runs to completion and prints true for the `isAlive` call in the end. Am I missing something?

        Env: Java(TM) SE Runtime Environment (build 9-ea+157-jigsaw-nightly-h6122-20170221) on MacOS.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rriggs Roger Riggs
                  Reporter:
                  chegar Chris Hegarty
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: