I am attempting to implement the functionality of starting and stopping monitoring a given process by periodically displaying its CPU and Memory usage.

Through this line of code, I can obtain the list of processes that are currently running on the system, and I parse the list (which is returned as a string) and create objects stored in a HashMap.

Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\tasklist.exe");

The key of the HashMap is the process name, and the value is the object created from that process name. The information stored in that object is the process name, PID, sessionName, sessionNumber, and memoryUsage.

private static HashMap<String, ProcessDetails> processHashMap;//ProcessDetails is the class that I have created to hold the information about the process (parameters are stated above).

My question is, how can I start or stop monitoring that process? I need to be able to start or stop monitoring a given running process by periodically displaying the CPU and memory usage.

I'd like to add that this program is only a Windows program so it will not run on another OS.