Reputation: 1281
I'm working on a C++ program and I want to find the total memory used by it in its execution. My operating system is Ubuntu 19.10. I found this as a related question, but it seems to address a much different problem. Any help/directions would be great. Thanks!
Upvotes: 1
Views: 176
Reputation: 337
As you mentioned in the comments section of your own question, we can use the command line program GNU time
for this.
Though note this method only is useful if you want to know the maximum memory your program has used before it stopped, which can be useful to confirm that an executable you are debugging has an over-time memory leak.
If you want to monitor in real-time then I recommend @spjy's method.
Obtain it through whatever package manager you have on your linux distro.
Note that by default on a linux system it comes with a default version of time, and thus if you run time
it will run the default version, not the one you just installed.
If want to run you're installed version you can call it directly /usr/bin/time
. Then the command you need is
/usr/bin/time -v <path to executable>
After the command has completed take a look at the line Maximum resident set size (kbytes)
to see how much memory your program used at most.
Upvotes: 0
Reputation: 467
You can use the command line tool top
to monitor the memory usage of a process. Simply run:
top -p PID
where PID
is the process ID of the C++ executable that you want to monitor the memory usage of.
Upvotes: 1