blob: 311c4e74f7a783c24119c7788aa08d1495adff4b [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001import java.util.Map;
2
3public class Main {
4 static public void main(String[] args) throws Exception {
5 checkManager();
6 for (int i = 1; i <= 2; i++) {
7 System.out.println("\nspawning child #" + i);
8 child();
9 Thread.sleep(2000);
10 checkManager();
11 }
12 System.out.println("\ndone!");
13 }
14
15 static private void child() throws Exception {
16 System.out.println("spawning child");
TDYa1276ce558b2012-04-11 11:17:55 -070017 ProcessBuilder pb = new ProcessBuilder("sleep", "5");
jeffhao5d1ac922011-09-29 17:41:15 -070018 Process proc = pb.start();
Jeff Hao584a2db2017-08-17 15:06:44 -070019 Thread.sleep(2000);
jeffhao5d1ac922011-09-29 17:41:15 -070020 checkManager();
21 proc.waitFor();
22 System.out.println("child died");
23 }
24
25 static private void checkManager() {
26 Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
27 boolean found = false;
28
29 for (Map.Entry<Thread, StackTraceElement[]> entry :
30 traces.entrySet()) {
31 Thread t = entry.getKey();
32 String name = t.getName();
Narayan Kamathcad42052015-11-16 14:51:16 +000033 if (name.indexOf("process reaper") >= 0) {
jeffhao5d1ac922011-09-29 17:41:15 -070034 System.out.println("process manager: " + t.getState());
35 found = true;
36 }
37 }
38
39 if (! found) {
40 System.out.println("process manager: nonexistent");
41 }
42 }
43}