3261N/A * Copyright (c) 1995, 2010, 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 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/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. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 2473N/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 /* this is for the reaping thread */ 25N/A * Create a process using fork(2) and exec(2). 2473N/A * @param fds an array of three file descriptors. 2473N/A * Indexes 0, 1, and 2 correspond to standard input, 2473N/A * standard output and standard error, respectively. On 2473N/A * input, a value of -1 means to create a pipe to connect 2473N/A * child and parent processes. On output, a value which 2473N/A * is not -1 is the parent pipe fd corresponding to the 2473N/A * pipe which has been created. An element of this array 2473N/A * is -1 on input if and only if it is <em>not</em> -1 on 25N/A * @return the pid of the subprocess 2473N/A * The thread factory used to create "process reaper" daemon threads. 2473N/A // Our thread stack requirement is quite modest. 2473N/A // A small attempt (probably futile) to avoid priority inversion 2473N/A * The thread pool of "process reaper" daemon threads. 25N/A // There is a risk that pid will be recycled, causing us to 25N/A // kill the wrong process! So we only terminate processes 25N/A // that appear to still be running. Even with this check, 25N/A // there is an unavoidable race condition here, but the window 25N/A // is very small, and OSes try hard to not recycle pids too 25N/A // soon, so this is quite safe. 25N/A synchronized (
this) {
0N/A /* This routine initializes JNI field offsets for the class */ 2473N/A * A buffered input stream for a subprocess pipe file descriptor 2473N/A * that allows the underlying file descriptor to be reclaimed when 2473N/A * the process exits, via the processExited hook. 2473N/A * This is tricky because we do not want the user-level InputStream to be 2473N/A * closed until the user invokes close(), and we need to continue to be 2473N/A * able to read any buffered data lingering in the OS pipe buffer. 2473N/A /** Called by the process reaper thread when the process exits. */ 2473N/A // Most BufferedInputStream methods are synchronized, but close() 2473N/A // is not, and so we have to handle concurrent racing close(). 2473N/A // probably an asynchronous close(). 2473N/A * A buffered output stream for a subprocess pipe file descriptor 2473N/A * that allows the underlying file descriptor to be reclaimed when 2473N/A * the process exits, via the processExited hook. 2473N/A /** Called by the process reaper thread when the process exits. */ 2473N/A // We know of no reason to get an IOException, but if 2473N/A // we do, there's nothing else to do but carry on.