test/java/lang/Runtime/exec/SleepyCat.java
Print this page
*** 71,82 ****
// reproducible not only for the obvious reason, but also for
// the subtle reason that it makes reading /proc/getppid()/fd
// slower, making the child more likely to win the race!
int iterations = 20;
int timeout = 30;
! String[] catArgs = new String[] {"/bin/cat"};
! String[] sleepArgs = new String[] {"/bin/sleep",
String.valueOf(timeout+1)};
Process[] cats = new Process[iterations];
Process[] sleeps = new Process[iterations];
Timer timer = new Timer(true);
TimeoutTask catExecutioner = new TimeoutTask(cats);
--- 71,82 ----
// reproducible not only for the obvious reason, but also for
// the subtle reason that it makes reading /proc/getppid()/fd
// slower, making the child more likely to win the race!
int iterations = 20;
int timeout = 30;
! String[] catArgs = new String[] {UnixCommands.cat()};
! String[] sleepArgs = new String[] {UnixCommands.sleep(),
String.valueOf(timeout+1)};
Process[] cats = new Process[iterations];
Process[] sleeps = new Process[iterations];
Timer timer = new Timer(true);
TimeoutTask catExecutioner = new TimeoutTask(cats);
*** 124,135 ****
Process[] backgroundSleepers = new Process[iterations];
TimeoutTask sleeperExecutioner = new TimeoutTask(backgroundSleepers);
timer.schedule(sleeperExecutioner, timeout * 1000);
byte[] buffer = new byte[10];
String[] args =
! new String[] {"/bin/sh", "-c",
! "exec sleep " + (timeout+1) + " >/dev/null"};
for (int i = 0;
i < backgroundSleepers.length && !sleeperExecutioner.timedOut();
++i) {
backgroundSleepers[i] = rt.exec(args); // race condition here
--- 124,136 ----
Process[] backgroundSleepers = new Process[iterations];
TimeoutTask sleeperExecutioner = new TimeoutTask(backgroundSleepers);
timer.schedule(sleeperExecutioner, timeout * 1000);
byte[] buffer = new byte[10];
String[] args =
! new String[] {UnixCommands.sh(), "-c",
! "exec " + UnixCommands.sleep() + " "
! + (timeout+1) + " >/dev/null"};
for (int i = 0;
i < backgroundSleepers.length && !sleeperExecutioner.timedOut();
++i) {
backgroundSleepers[i] = rt.exec(args); // race condition here
*** 151,164 ****
System.out.println("Child process has two (should be one) writable pipe fds for its stdout.");
return sleeperExecutioner.timedOut();
}
public static void main (String[] args) throws Exception {
! try {
if (hang1() | hang2())
throw new Exception("Read from closed pipe hangs");
- } catch (IOException e) {
- // We will get here on non-Posix systems,
- // which don't have cat and sleep and sh.
- }
}
}
--- 152,166 ----
System.out.println("Child process has two (should be one) writable pipe fds for its stdout.");
return sleeperExecutioner.timedOut();
}
public static void main (String[] args) throws Exception {
! if (! UnixCommands.isUnix) {
! System.out.println("For UNIX only");
! return;
! }
! UnixCommands.ensureCommandsAvailable("sh", "cat", "sleep");
!
if (hang1() | hang2())
throw new Exception("Read from closed pipe hangs");
}
}