views:

239

answers:

3

Is there a way using Java that I can gain a list of all active processes running on a Mac?

I can do so in Windows using the code below to return the Task List, but that throws an exception on a Mac. I want my app to stop if certain applications are also running.

Any ideas? Thanks.

Windows Code:

Process p = Runtime.getRuntime().exec("tasklist.exe /nh");
      BufferedReader input = new BufferedReader
      (new InputStreamReader(p.getInputStream()));

      //while there are more processes in the task manager list
      while ((line = input.readLine()) != null) {
                      //insert code here for each task running
            }
+1  A: 

tasklist.exe does not exist on Mac. Use something like ps -eaf

Alan
I need to monitor processes programmatically. Is there any way to do this? I do not know is typing that command into the Terminal will return to my program an array of some sort with all the process names.
A: 

Thank you for the information above. The command line is actually "ps x" I learned. I can replace "tasklist.exe" in the code above with "ps x" to get the app path for each process and parse it.

A: 

Hi there, I need to monitor all the system process ex open a one word application note the time when i close the application monitor the time for all task simply said monitor the task manager fully through java back ground is there any way give me the idea thanks in advance...

Raja K.S