So, how can I check if a process is running in Java?
I'm running a private server of some game...
And I got the player's IP and the port that they are using to connect..
Thanks in-advance.
EDIT:
I am using Windows 7, and again, I need to get the client's processes information
and then determine if the process is running or not, and not my server's computer
processes.. :/
any ideas?? :(
You can use
Process proc = Runtime.getRuntime().exec("ps -e");
Then use proc.getInputStream() to read the output of the command.
BTW the above command is for linux
for windows I believe the command is "tasklist"
You can use the wmic utility to check the list of running processes. Suppose you want to check if the windows' explorer.exe process is running :
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();
}
See http://ss64.com/nt/wmic.html or http://support.microsoft.com/servicedesks/webcasts/wc072402/listofsampleusage.asp for some example of what you can get from wmic...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.