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

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

  •  01-06-2022
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top