Linux – How to know how much memory a program has used under Linux

clinuxmemory

Get process memory consumption this question is about getting the memory usage of running program. I need to know how much RAM a program has used after it has finished.

Say I am compiling a C++ program with this command g++ main.cpp. I need to know how much memory this used after it has finished. Or, if memory can only be measured for a specific instant, I need to know what is the maximum RAM usage when compiling a program.

For any program I passed to /usr/bin/time -f "%M", I get max resident value 0. I am sure that my program uses gigabytes of memory

Best Answer

Run the program under /usr/bin/time and look at the max resident value. You need to specify the full path to avoid using the simpler builtin time command.

Related Question