UNIXProcess.java.linux revision 2473
0N/A * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * java.lang.Process subclass in the UNIX environment. 0N/A * @author Mario Wolczko and Ross Knippel. 0N/A * @author Konstantin Kladko (ported to Linux) 0N/A * @author Martin Buchholz /* this is for the reaping thread */ * Create a process using fork(2) and exec(2). * @param fds an array of three file descriptors. * Indexes 0, 1, and 2 correspond to standard input, * standard output and standard error, respectively. On * input, a value of -1 means to create a pipe to connect * child and parent processes. On output, a value which * is not -1 is the parent pipe fd corresponding to the * pipe which has been created. An element of this array * is -1 on input if and only if it is <em>not</em> -1 on * @return the pid of the subprocess * The thread factory used to create "process reaper" daemon threads. // Our thread stack requirement is quite modest. // A small attempt (probably futile) to avoid priority inversion * The thread pool of "process reaper" daemon threads. // 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, // there is an unavoidable race condition here, but the window // is very small, and OSes try hard to not recycle pids too // soon, so this is quite safe. /* This routine initializes JNI field offsets for the class */ private static native void initIDs();
* A buffered input stream for a subprocess pipe file descriptor * that allows the underlying file descriptor to be reclaimed when * the process exits, via the processExited hook. * This is tricky because we do not want the user-level InputStream to be * closed until the user invokes close(), and we need to continue to be * able to read any buffered data lingering in the OS pipe buffer. /** Called by the process reaper thread when the process exits. */ // Most BufferedInputStream methods are synchronized, but close() // is not, and so we have to handle concurrent racing close(). if (
buf ==
null)
// asynchronous close()? // probably an asynchronous close(). * A buffered output stream for a subprocess pipe file descriptor * that allows the underlying file descriptor to be reclaimed when * the process exits, via the processExited hook. /** Called by the process reaper thread when the process exits. */ // We know of no reason to get an IOException, but if // we do, there's nothing else to do but carry on.