user1193134
user1193134

Reputation: 163

Howto get memory usage of a started process


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!

Upvotes: 2

Views: 1743

Answers (3)

user1193134
user1193134

Reputation: 163

This question here including

   ProcessBuilder pb = new ProcessBuilder("cmd.exe",  "/C", "tasklist /fi \"IMAGENAME eq notepad.exe\" /NH");

solved my problem.

Upvotes: 0

P. Lalonde
P. Lalonde

Reputation: 694

You could run a system command and dump it's output in a file. Then, parse this file to find the memory usage.

Upvotes: 1

Philipp Sander
Philipp Sander

Reputation: 10249

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.

Upvotes: 1

Related Questions