test/java/lang/ProcessBuilder/Basic.java

Print this page

        

*** 2015,2025 **** try { if (Unix.is() && new File("/bin/bash").exists() && new File("/bin/sleep").exists()) { final String[] cmd = { "/bin/bash", "-c", "(/bin/sleep 6666)" }; - final String[] cmdkill = { "/bin/bash", "-c", "(/usr/bin/pkill -f \"sleep 6666\")" }; final ProcessBuilder pb = new ProcessBuilder(cmd); final Process p = pb.start(); final InputStream stdout = p.getInputStream(); final InputStream stderr = p.getErrorStream(); final OutputStream stdin = p.getOutputStream(); --- 2015,2024 ----
*** 2043,2059 **** check(p.waitFor() != 0); check(p.exitValue() != 0); stdout.close(); stderr.close(); stdin.close(); - new ProcessBuilder(cmdkill).start(); //---------------------------------------------------------- // There remain unsolved issues with asynchronous close. // Here's a highly non-portable experiment to demonstrate: //---------------------------------------------------------- if (Boolean.getBoolean("wakeupJeff!")) { System.out.println("wakeupJeff!"); // Initialize signal handler for INTERRUPT_SIGNAL. new FileInputStream("/bin/sleep").getChannel().close(); // Send INTERRUPT_SIGNAL to every thread in this java. String[] wakeupJeff = { "/bin/bash", "-c", --- 2042,2058 ---- check(p.waitFor() != 0); check(p.exitValue() != 0); stdout.close(); stderr.close(); stdin.close(); //---------------------------------------------------------- // There remain unsolved issues with asynchronous close. // Here's a highly non-portable experiment to demonstrate: //---------------------------------------------------------- if (Boolean.getBoolean("wakeupJeff!")) { System.out.println("wakeupJeff!"); + long startTime = System.nanoTime(); // Initialize signal handler for INTERRUPT_SIGNAL. new FileInputStream("/bin/sleep").getChannel().close(); // Send INTERRUPT_SIGNAL to every thread in this java. String[] wakeupJeff = { "/bin/bash", "-c",
*** 2062,2073 **** // INTERRUPT_SIGNAL == 62 on my machine du jour. "/usr/bin/xargs kill -62" }; new ProcessBuilder(wakeupJeff).start().waitFor(); // If wakeupJeff worked, reader probably got EBADF. ! reader.join(); } } } catch (Throwable t) { unexpected(t); } //---------------------------------------------------------------- // Attempt to start process with insufficient permissions fails. --- 2061,2081 ---- // INTERRUPT_SIGNAL == 62 on my machine du jour. "/usr/bin/xargs kill -62" }; new ProcessBuilder(wakeupJeff).start().waitFor(); // If wakeupJeff worked, reader probably got EBADF. ! long timeout = 60L * 1000L; ! reader.join(timeout); ! long elapsedTimeMillis = ! (System.nanoTime() - startTime) / (1024L * 1024L); ! check(elapsedTimeMillis < timeout); ! check(!reader.isAlive()); } + // Try to clean up the sleep process, but don't fret about it. + try { + new ProcessBuilder("/usr/bin/pkill", "-f", "sleep 6666").start(); + } catch (IOException noPkillCommandInstalled) { } } } catch (Throwable t) { unexpected(t); } //---------------------------------------------------------------- // Attempt to start process with insufficient permissions fails.