Check if process is running on windows/linux

后端 未结 7 2146
一生所求
一生所求 2020-12-10 15:30

i have a process

Runtime rt = Runtime.getRuntime() ;
Process p = rt.exec(filebase+port+\"/hlds.exe +ip \"+ip+\" +maxplayers \"+players+ \" -game cstrike -co         


        
7条回答
  •  伪装坚强ぢ
    2020-12-10 15:52

    You can do a p.waitFor() so the thread that executed the statement waits till the process is complete. You can then do the cleanup/restart logic right after, as that code will get executed when the process dies. However I am not sure how this would work if the process hangs instead of dying, but this could be worth a try. By the way I would recommend using Java Service Wrapper and supervisord in your case if this is something you're going to do on production.

提交回复
热议问题