--- old/src/solaris/classes/java/lang/UNIXProcess.java.solaris Thu May 31 14:50:28 2012 +++ new/src/solaris/classes/java/lang/UNIXProcess.java.solaris Thu May 31 14:50:27 2012 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.lang; import java.io.*; +import java.util.concurrent.TimeUnit; /* java.lang.Process subclass in the UNIX environment. * @@ -157,6 +158,25 @@ } return exitcode; } + + @Override + public synchronized boolean waitFor(long timeout, TimeUnit unit) + throws InterruptedException { + if (hasExited) return true; + if (timeout <= 0) return false; + + long now = System.nanoTime(); + long end = now + TimeUnit.NANOSECONDS.convert(timeout, unit); + if (end <= 0) // overflow + end = Long.MAX_VALUE; + + long rem = end - now; + while (!hasExited && (rem > 0)) { + wait(Math.max(TimeUnit.NANOSECONDS.toMillis(rem), 1)); + rem = end - System.nanoTime(); + } + return hasExited; + } public synchronized int exitValue() { if (!hasExited) { @@ -165,8 +185,8 @@ return exitcode; } - private static native void destroyProcess(int pid); - public synchronized void destroy() { + private static native void destroyProcess(int pid, boolean force); + private synchronized void destroy(boolean force) { // There is a risk that pid will be recycled, causing us to // kill the wrong process! So we only terminate processes // that appear to still be running. Even with this check, @@ -174,7 +194,7 @@ // is very small, and OSes try hard to not recycle pids too // soon, so this is quite safe. if (!hasExited) - destroyProcess(pid); + destroyProcess(pid, force); try { stdin_stream.close(); if (stdout_inner_stream != null) @@ -187,6 +207,21 @@ } } + public void destroy() { + destroy(false); + } + + @Override + public Process destroyForcibly() { + destroy(true); + return this; + } + + @Override + public synchronized boolean isAlive() { + return !hasExited; + } + // A FileInputStream that supports the deferment of the actual close // operation until the last pending I/O operation on the stream has // finished. This is required on Solaris because we must close the stdin