62,614
社区成员
发帖
与我相关
我的任务
分享
public class ProcessState extends Thread {
public ProcessState(Process p) {
process = p;
}
@Override
public void run() {
try {
process.waitFor();
} catch (InterruptedException ex) {
throw new RuntimeException();
}
}
public void startListen() {
start();
}
public boolean isExit() {
switch (getState()) {
case NEW:
throw new RuntimeException();
case TERMINATED:
return true;
default:
return false;
}
}
private Process process;
}
Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
process = runtime.exec("cmd /c Tasklist");
BufferedReader in = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String s = "";
while ((s = in.readLine()) != null) {
//看看有没有想要的进程
}
}