How to get process (external program) time, cpu usage for process run from java application?

StackOverflow https://stackoverflow.com/questions/17188093

  •  01-06-2022
  •  | 
  •  

Question

I know how to run an external program in java:

public class Test {
  public static void main(String[] args) throws Exception {
    Process p = Runtime.getRuntime().exec(
       "\"c:/my-simple-app.exe\"");
    p.waitFor();
  }
}

But how can I get all of the program properties when I run it like this? I mean: system time for this process (how much system time it took to run), cpu usage (only for this exact process), ... Is it possible?

Était-ce utile?

La solution

Run this program in a separate thread, then run tasklist /v process (if Windows), intercept output, split lines into columns, find my-simple-app.exe and get necessary info. If tasklist info is not enough, then read process ID column form tasklist output and run some other util to get more info.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top