我有一个过程
Runtime rt = Runtime.getRuntime() ;
Process p = rt.exec(filebase+port+"/hlds.exe +ip "+ip+" +maxplayers "+players+ " -game cstrike -console +port "+port+" -nojoy -noipx -heapsize 250000 +map de_dust2 +servercfgfile server.cfg +lservercfgfile +mapcyclefile mapcycle.txt +motdfile motd.txt +logsdir logs -zone 2048",null, new File(filebase+port)) ;
我想检查此进程是否正在运行或是否已崩溃以防崩溃想要重新启动它,此进程可以有多个实例可用,具体取决于端口
我可以在 Linux 和 Windows 上跟踪这个东西吗?阅读一些关于它的文章,但是这个 1 有点不同,因为它涉及多次出现并且只需要检查一些特定的过程
最佳答案
boolean isRunning(Process process) {
try {
process.exitValue();
return false;
} catch (Exception e) {
return true;
}
}
参见 http://docs.oracle.com/javase/6/docs/api/java/lang/Process.html#exitValue()
关于java - 检查进程是否在 windows/linux 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5799424/