写道
public class ProcessMonitorTools {
private Process process;
public void startCalcul(){
try {
process=Runtime.getRuntime().exec("notepad");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getCalculStatus(){
int status;
try{
status=process.exitValue();
}catch(IllegalThreadStateException e){
return "process";
}
if(status==0){
return "end";}
else{
return "error";
}
}
public void shutDownProcess(){
process.destroy();
}
}
private Process process;
public void startCalcul(){
try {
process=Runtime.getRuntime().exec("notepad");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getCalculStatus(){
int status;
try{
status=process.exitValue();
}catch(IllegalThreadStateException e){
return "process";
}
if(status==0){
return "end";}
else{
return "error";
}
}
public void shutDownProcess(){
process.destroy();
}
}
比较简单,主要关键地方在于标红的地方,可以判断process的状态,是处于正常结束,异常退出,还是正在运行的,