[英]How to check if a process is running on a client's computer (on server-side)? [Java]
那么,如何檢查進程是否正在Java中運行?
我正在運行一些游戲的私人服務器...
我得到了播放器的IP以及他們用來連接的端口。
提前致謝。
編輯:
我正在使用Windows 7,再次,我需要獲取客戶端的進程信息
然后確定該進程是否正在運行,而不是服務器的計算機
進程..:/
有任何想法嗎?? :(
您可以使用
Process proc = Runtime.getRuntime().exec("ps -e");
然后使用proc.getInputStream()讀取命令的輸出。
順便說一句,上面的命令是針對Linux的
對於Windows,我相信命令是“任務列表”
您可以使用wmic實用程序來檢查正在運行的進程的列表。 假設您要檢查Windows的explorer.exe進程是否正在運行:
String line;
try {
Process proc = Runtime.getRuntime().exec("wmic.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());
oStream .write("process where name='explorer.exe'");
oStream .flush();
oStream .close();
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
請參閱http://ss64.com/nt/wmic.html或http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp,以獲取可從wmic獲得的一些示例...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.