2009年9月14日

Java Kill process

Microsoft Windows XP - Taskkill
Kill process in Linux or terminate a process in UNIX or Linux systems

//-- Main.java --
import java.io.IOException;

public class Main {

public static void main(String[] args) throws IOException {
String osName = System.getProperty("os.name");
String name = args[0];
String[] commands = null;
if (osName.startsWith("Windows")) {
commands = new String[] { "TASKKILL", "/F", "/T", "/IM", name };
} else {
commands = new String[] { "/usr/bin/killall", "-9", name };
}
ProcessBuilder pb = new ProcessBuilder();
pb.command(commands);
pb.start();
}

}

沒有留言:

網誌存檔