I try to get the memory usage of a process started via Java.
Can someone give me a hint how to do it for the example Notepad.exe?
// Memoryusage of the Java programm
Runtime runtime=Runtime.getRuntime();
total = runtime.totalMemory();
System.out.println("System Memory: " + total);
ProcessBuilder builder = new ProcessBuilder("notepad.exe");
Process p = builder.start();
Thanks for your help!
this post has your answer
Java ProcessBuilder memory
quoting top answer:
The new process runs outside the Java process that started it. Allocation of memory to the new process is managed by the operating system, as part of process management.
The Java class ProcessBuilder, which provides an interface for starting and communicating with the new process, runs inside the Java process.
You could run a system command and dump it's output in a file.
Then, parse this file to find the memory usage.
This question here including
ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "tasklist /fi \"IMAGENAME eq notepad.exe\" /NH");
solved my problem.