Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取Runtime.getRuntime().exec()使用的内存_Java_Memory_Process_Runtime - Fatal编程技术网

Java 获取Runtime.getRuntime().exec()使用的内存

Java 获取Runtime.getRuntime().exec()使用的内存,java,memory,process,runtime,Java,Memory,Process,Runtime,我正在使用java,我想管理进程的已用内存。我使用了Runtime.getRuntime().exec()以运行应用程序。例如: Runtime.getRuntime().exec("/home/bangjdev/testapp"); // on Linux import java.io.IOException; public class Main { public static void main(String args[]) { Runtime rt = Runt

我正在使用java,我想管理进程的已用内存。我使用了
Runtime.getRuntime().exec()以运行应用程序。例如:

Runtime.getRuntime().exec("/home/bangjdev/testapp"); // on Linux
import java.io.IOException;

public class Main {
    public static void main(String args[]) {
        Runtime rt = Runtime.getRuntime();
        long bfore = rt.freeMemory();
        try {
            rt.exec("/home/bangjdev/Documents/test");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        long after = rt.freeMemory();

        System.out.println("Used " + (bfore - after) + " bytes");
    }
}
现在的问题是:我想知道这个进程使用了多少内存? 我曾尝试使用freeMemory(),但似乎不是这样,例如:

Runtime.getRuntime().exec("/home/bangjdev/testapp"); // on Linux
import java.io.IOException;

public class Main {
    public static void main(String args[]) {
        Runtime rt = Runtime.getRuntime();
        long bfore = rt.freeMemory();
        try {
            rt.exec("/home/bangjdev/Documents/test");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        long after = rt.freeMemory();

        System.out.println("Used " + (bfore - after) + " bytes");
    }
}

请看这里:@bang您想知道启动进程的内存使用情况还是您的java进程?我非常想知道启动进程的内存使用情况任何人都可以帮助我:(