Using Java to retrieve the CPU Usage for Window's Processes

Stephen Watkins picture Stephen Watkins · Nov 20, 2009 · Viewed 8.9k times · Source

I am looking for a Java solution to finding the CPU usage for a running process in Windows. After looking around the web, there seems to be little information on a solution in Java. Keep in mind, I am not looking to find the CPU usage for the JVM, but any process running in Windows at the time.

I am able to retrieve the memory usage in Java by using the exec("tasklist.exe ... ") to retrieve and parse process information. Although there is an aggregate CPU cycle timer for each process, I do not see a CPU usage column.

Any help would be greatly appreciated. Also, if possible, I would like to stay away from C libraries; however, if there is no other alternative, a solution by that means would be appropriate.

Thanks a lot,

Steve

Answer

bmargulies picture bmargulies · Nov 20, 2009

Look into Jacob. It will let you call COM objects, and there are COM objects galore for this kind of information on Windows.