jdk/test/java/lang/ProcessBuilder/DestroyTest.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 13149 27d52f97a5cc
child 22597 7515a991bb37
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13149
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     1
/*
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     4
 *
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     8
 *
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    13
 * accompanied this code).
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    14
 *
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    18
 *
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    21
 * questions.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    22
 */
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    23
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    24
/*
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    25
 * @test
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    26
 * @bug 4244896
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    27
 * @summary Test for the various platform specific implementations of
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    28
 *          destroyForcibly.
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    29
 */
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    30
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    31
import java.io.*;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    32
import java.util.ArrayList;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    33
import java.util.concurrent.TimeUnit;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    34
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    35
abstract class ProcessTest implements Runnable {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    36
    ProcessBuilder bldr;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    37
    Process p;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    38
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    39
    public Process killProc(boolean force) throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    40
        if (force) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    41
            p.destroyForcibly();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    42
        } else {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    43
            p.destroy();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    44
        }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    45
        return p;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    46
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    47
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    48
    public boolean isAlive() {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    49
        return p.isAlive();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    50
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    51
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    52
    public void run() {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    53
        try {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    54
            String line;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    55
            BufferedReader is =
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    56
                new BufferedReader(new InputStreamReader(p.getInputStream()));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    57
            while ((line = is.readLine()) != null)
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    58
                System.err.println("ProcessTrap: " + line);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    59
        } catch(IOException e) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    60
            if (!e.getMessage().matches("[Ss]tream [Cc]losed")) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    61
                throw new RuntimeException(e);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    62
            }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    63
        }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    64
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    65
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    66
    public abstract void runTest() throws Exception;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    67
}
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    68
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    69
class UnixTest extends ProcessTest {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    70
    public UnixTest(File script) throws IOException {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    71
        script.deleteOnExit();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    72
        createScript(script);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    73
        bldr = new ProcessBuilder(script.getCanonicalPath());
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    74
        bldr.redirectErrorStream(true);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    75
        bldr.directory(new File("."));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    76
        p = bldr.start();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    77
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    78
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    79
    void createScript(File processTrapScript) throws IOException {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    80
        processTrapScript.deleteOnExit();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    81
        FileWriter fstream = new FileWriter(processTrapScript);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    82
        try (BufferedWriter out = new BufferedWriter(fstream)) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    83
            out.write("#!/bin/bash\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    84
                "echo \\\"ProcessTrap.sh started: trapping SIGTERM/SIGINT\\\"\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    85
                "trap bashtrap SIGTERM SIGINT\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    86
                "bashtrap()\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    87
                "{\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    88
                "    echo \\\"SIGTERM/SIGINT detected!\\\"\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    89
                "}\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    90
                "\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    91
                "while :\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    92
                "do\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    93
                "    sleep 1;\n" +
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    94
                "done\n");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    95
        }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    96
        processTrapScript.setExecutable(true, true);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    97
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    98
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
    99
    @Override
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   100
    public void runTest() throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   101
        killProc(false);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   102
        Thread.sleep(1000);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   103
        if (!p.isAlive())
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   104
            throw new RuntimeException("Process terminated prematurely.");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   105
        killProc(true).waitFor();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   106
        if (p.isAlive())
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   107
            throw new RuntimeException("Problem terminating the process.");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   108
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   109
}
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   110
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   111
class MacTest extends UnixTest {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   112
    public MacTest(File script) throws IOException {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   113
        super(script);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   114
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   115
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   116
    @Override
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   117
    public void runTest() throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   118
        // On Mac, it appears that when we close the processes streams
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   119
        // after a destroy() call, the process terminates with a
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   120
        // SIGPIPE even if it was trapping the SIGTERM, so as with
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   121
        // windows, we skip the trap test and go straight to destroyForcibly().
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   122
        killProc(true).waitFor();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   123
        if (p.isAlive())
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   124
            throw new RuntimeException("Problem terminating the process.");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   125
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   126
}
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   127
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   128
class WindowsTest extends ProcessTest {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   129
    public WindowsTest() throws IOException {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   130
        bldr = new ProcessBuilder("ftp");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   131
        bldr.redirectErrorStream(true);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   132
        bldr.directory(new File("."));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   133
        p = bldr.start();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   134
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   135
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   136
    @Override
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   137
    public void runTest() throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   138
        killProc(true).waitFor();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   139
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   140
}
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   141
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   142
public class DestroyTest {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   143
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   144
    public static ProcessTest getTest() throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   145
        String osName = System.getProperty("os.name");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   146
        if (osName.startsWith("Windows")) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   147
            return new WindowsTest();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   148
        } else if (osName.startsWith("Linux") == true) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   149
            return new UnixTest(
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   150
                File.createTempFile("ProcessTrap-", ".sh",null));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   151
        } else if (osName.startsWith("Mac OS")) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   152
            return new MacTest(
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   153
                File.createTempFile("ProcessTrap-", ".sh",null));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   154
        } else if (osName.equals("SunOS")) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   155
            return new UnixTest(
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   156
                File.createTempFile("ProcessTrap-", ".sh",null));
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   157
        }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   158
        return null;
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   159
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   160
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   161
    public static void main(String args[]) throws Exception {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   162
        ProcessTest test = getTest();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   163
        if (test == null) {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   164
            throw new RuntimeException("Unrecognised OS");
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   165
        } else {
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   166
            new Thread(test).start();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   167
            Thread.sleep(1000);
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   168
            test.runTest();
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   169
        }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   170
    }
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   171
}
27d52f97a5cc 4244896: (process) Provide System.getPid(), System.killProcess(String pid)
robm
parents:
diff changeset
   172