Howto get memory usage of a started process

蓝咒 提交于 2019-12-12 17:05:55

问题



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!


回答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.




回答2:


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




回答3:


This question here including

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

solved my problem.



来源:https://stackoverflow.com/questions/16238121/howto-get-memory-usage-of-a-started-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!