近段工作用到了线程方面的东西,拿出一些来和大家进行分享下,这里主要是通过pid来kill进程,以下是方法
public void killByPid(String str) {
final String[] Array = { "ntsd.exe", "-c", "q", "-p", str };
int i = 0;
try {
Process process = Runtime.getRuntime().exec(Array);
process.waitFor();
} catch (InterruptedException e) {
System.out.println("run err!");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (i != 0) {
try {
Process process = Runtime.getRuntime().exec(Array);
process.waitFor();
} catch (InterruptedException e) {
System.out.println("err!");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
参数为进程的pid,希望我的分享能给大家带来帮助