Skip to content

Instantly share code, notes, and snippets.

@LCamel
Created May 25, 2012 13:10
Show Gist options
  • Select an option

  • Save LCamel/2788046 to your computer and use it in GitHub Desktop.

Select an option

Save LCamel/2788046 to your computer and use it in GitHub Desktop.
Kill
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
runAndKill("java A", 3000);
}
public static void runAndKill(String cmd, final long millis) throws IOException, InterruptedException {
final Process proc = Runtime.getRuntime().exec(cmd);
new Thread() {
public void run() {
try {
Thread.sleep(millis);
proc.destroy();
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment