< prev index next >

src/solaris/classes/java/lang/UNIXProcess.java

Print this page
rev 13659 : 8208715: Conversion of milliseconds to nanoseconds in UNIXProcess contains bug
   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 391     }
 392 
 393     public synchronized int waitFor() throws InterruptedException {
 394         while (!hasExited) {
 395             wait();
 396         }
 397         return exitcode;
 398     }
 399 
 400     @Override
 401     public synchronized boolean waitFor(long timeout, TimeUnit unit)
 402         throws InterruptedException
 403     {
 404         if (hasExited) return true;
 405         if (timeout <= 0) return false;
 406 
 407         long remainingNanos = unit.toNanos(timeout);
 408         long deadline = System.nanoTime() + remainingNanos;
 409 
 410         do {
 411             // Round up to next millisecond
 412             wait(TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L));
 413             if (hasExited) {
 414                 return true;
 415             }
 416             remainingNanos = deadline - System.nanoTime();
 417         } while (remainingNanos > 0);
 418         return hasExited;
 419     }
 420 
 421     public synchronized int exitValue() {
 422         if (!hasExited) {
 423             throw new IllegalThreadStateException("process hasn't exited");
 424         }
 425         return exitcode;
 426     }
 427 
 428     private static native void destroyProcess(int pid, boolean force);
 429 
 430     private void destroy(boolean force) {
 431         switch (platform) {
 432             case LINUX:


   1 /*
   2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 391     }
 392 
 393     public synchronized int waitFor() throws InterruptedException {
 394         while (!hasExited) {
 395             wait();
 396         }
 397         return exitcode;
 398     }
 399 
 400     @Override
 401     public synchronized boolean waitFor(long timeout, TimeUnit unit)
 402         throws InterruptedException
 403     {
 404         if (hasExited) return true;
 405         if (timeout <= 0) return false;
 406 
 407         long remainingNanos = unit.toNanos(timeout);
 408         long deadline = System.nanoTime() + remainingNanos;
 409 
 410         do {
 411             TimeUnit.NANOSECONDS.timedWait(this, remainingNanos);

 412             if (hasExited) {
 413                 return true;
 414             }
 415             remainingNanos = deadline - System.nanoTime();
 416         } while (remainingNanos > 0);
 417         return hasExited;
 418     }
 419 
 420     public synchronized int exitValue() {
 421         if (!hasExited) {
 422             throw new IllegalThreadStateException("process hasn't exited");
 423         }
 424         return exitcode;
 425     }
 426 
 427     private static native void destroyProcess(int pid, boolean force);
 428 
 429     private void destroy(boolean force) {
 430         switch (platform) {
 431             case LINUX:


< prev index next >