3

I'm using java and I want to manage used memory of Process. I used Runtime.getRuntime().exec(); to run an application. For example:

Runtime.getRuntime().exec("/home/bangjdev/testapp"); // on Linux

Now the problem is: I want to know how much memory this Process used? I have tried to used freeMemory() but it seems not true, for example:

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");
    }
}
Hash
  • 4,647
  • 5
  • 21
  • 39
Bang
  • 51
  • 6

0 Answers0