public class TestProject {
//检测进程测试
public static void main(String[] args) {
new Thread(){
public void run(){
while(true){
try{
//cmd /c tasklist是要执行的命令
Process p = Runtime.getRuntime().exec("cmd /c tasklist");
/**
* 判断进程是否结束。如果结束则,p.waitFor()有返回值;否则无返回值;
* p.waitFor();等待进程死亡;
*/
p.waitFor();
System.err.println("Thread Over");
Thread.sleep(1000);
}catch(InterruptedException ie)
{
}
catch(java.io.IOException ioe){
}
}
}
}.start();
}
}
转载于:https://my.oschina.net/MStart/blog/517825