1

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?? :(

xStr0nGx
  • 13
  • 4

2 Answers2

0

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"

honerlawd
  • 1,499
  • 11
  • 10
-1

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...

Sinkingpoint
  • 7,449
  • 2
  • 29
  • 45
Natraj
  • 1
  • 7