test/java/lang/Runtime/exec/SleepyCat.java
Print this page
@@ -71,12 +71,12 @@
// 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[] 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,12 +124,13 @@
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"};
+ 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