2


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!

0

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So there is no other way then starting an other process (also outside of java) to get the memory usage?
not with java. you could try solving the problem with c oder c++
1

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

Comments

0

This question here including

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

solved my problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.