检查进程是否在 windows/linux 上运行 [英] Check if process is running on windows/linux

查看:29
本文介绍了检查进程是否在 windows/linux 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个过程

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)) ;

我想检查此进程是否正在运行或是否已崩溃,以便在崩溃的情况下重新启动它,此进程可以根据端口有多个可用实例

i want to keep a check on this process whether its running or has crashed in case of crash want to restart it, this Process can have multiple instance available depending upon the port

我可以在 Linux 和 Windows 上追踪这个东西吗?阅读一些关于它的文章,但这 1 篇有点不同,因为它涉及多次出现并且只需要检查某个特定过程

Can i trace this thing on Linux as well as on windows? Read some articles on it but this 1 is bit different, since it involves multiple occurrences and have to check on some particular process only

推荐答案

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()

这篇关于检查进程是否在 windows/linux 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆