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

查看:55
本文介绍了检查进程是否在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天全站免登陆