目前用windows系统 判断系统进程就通过Process执行Runtime的exc方法即windows的命令行
windows有条tasklist命令 FI方法过滤出匹配的过滤名称
tasklist /fi "imagename eq "public boolean isAlive(String procName) {
String cmd = "tasklist /fi \"" + "imagename eq " + procName + "\"";
Runtime r = Runtime.getRuntime();
Process p = null;
BufferedReader br = null;
try {
p = r.exec(cmd);
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
if (line.contains(procName)) {
return true;
}
}
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}