OSDN Git Service

2005-12-22 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / libjava.lang / Process_5.java
1 // Create a long running process and verify that the exitValue is not
2 // immediately available.  Then destroy() it and verify that it
3 // terminates quickly with a non-zero exitValue.
4 public class Process_5
5 {
6   public static void main(String[] args)
7   {
8     try
9       {
10         int c;
11         long startTime = System.currentTimeMillis();
12         Runtime r = Runtime.getRuntime();
13         String[] a = { "sleep", "120" };
14         Process p = r.exec(a);
15
16         try
17           {
18             c = p.exitValue();
19             System.out.println("bad 1");
20             return;
21           }
22         catch (IllegalThreadStateException itse)
23           {
24             // Ignore as this is good here.
25           }
26
27         p.destroy();
28
29         c = p.waitFor();
30
31         long endTime = System.currentTimeMillis();
32
33         if (endTime - startTime > 110000L)
34           System.out.println("bad 2");
35
36         System.out.println(c != 0 ? "ok" : "bad 3");
37       }
38     catch (Exception ex)
39       {
40         System.out.println(ex.toString());
41       }
42   }
43 }