UNIXProcess.java.solaris revision 25
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * This code is free software; you can redistribute it and/or modify it
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * under the terms of the GNU General Public License version 2 only, as
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * published by the Free Software Foundation. Sun designates this
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * particular file as subject to the "Classpath" exception as provided
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * by Sun in the LICENSE file that accompanied this code.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * This code is distributed in the hope that it will be useful, but WITHOUT
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * version 2 for more details (a copy is included in the LICENSE file that
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * accompanied this code).
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * You should have received a copy of the GNU General Public License version
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * 2 along with this work; if not, write to the Free Software Foundation,
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * CA 95054 USA or visit www.sun.com if you need additional information or
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * have any questions.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff/* java.lang.Process subclass in the UNIX environment.
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos * @author Mario Wolczko and Ross Knippel.
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff private final int pid;
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff private boolean hasExited;
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff private DeferredCloseInputStream stdout_inner_stream;
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff /* this is for the reaping thread */
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * Create a process using fork(2) and exec(2).
35cd0f38c7b43c813f9d4e5be555c5f9406fae2eAndi Egloff * @param std_fds array of file descriptors. Indexes 0, 1, and
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff * 2 correspond to standard input, standard output and
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * standard error, respectively. On input, a value of -1
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * means to create a pipe to connect child and parent
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * processes. On output, a value which is not -1 is the
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * parent pipe fd corresponding to the pipe which has
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * been created. An element of this array is -1 on input
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * if and only if it is <em>not</em> -1 on output.
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos * @return the pid of the subprocess
e13366e235a3af3029b751bc89f419ec1615fe30Andi Egloff final byte[] dir,
f572d33ed141953335fe796ca36d818146af68efLaszlo Hordos new java.security.PrivilegedAction<Void>() { public Void run() {
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos stdin_stream = new ProcessBuilder.NullOutputStream();
return null; }});
public void run() {
synchronized (UNIXProcess.this) {
hasExited = true;
t.setDaemon(true);
t.start();
return null; }});
return stdin_stream;
return stdout_stream;
return stderr_stream;
while (!hasExited) {
wait();
return exitcode;
public synchronized int exitValue() {
if (!hasExited) {
return exitcode;
public synchronized void destroy() {
if (!hasExited)
} catch (IOException e) {
private static class DeferredCloseInputStream
extends FileInputStream
super(fd);
private boolean closePending = false;
private void raise() {
synchronized (lock) {
useCount++;
synchronized (lock) {
useCount--;
synchronized (lock) {
closePending = true;
synchronized (lock) {
closePending = false;
super.close();
raise();
return super.read();
lower();
raise();
return super.read(b);
lower();
raise();
lower();
raise();
return super.skip(n);
lower();
raise();
return super.available();
lower();
private static native void initIDs();
initIDs();