Using /usr/bin/time always returns 0 when getting maximum resident memory
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using /usr/bin/time always returns 0 when getting maximum resident memory
Hi,
First time here at LQ, so if the post is in the wrong place, this is a bit programming related. I've been trying to find the maximum resident memory of a process in a memory constraint situation.
Instead of using top, or ps, which gives me real-time snapshot at the memory usage of a process, is there a way to determine the maximum resident memory used by a process?
/usr/bin/time seem to provide this functionality within the format string
time -f "%M" ./foo
gives
0
That is 0KB of resident memory, but I know the process will take more than 0KB of memory
foo is a compiled c++ code of the following
#include <map>
int main(){
std::map<int,double> tmp;
for(int i = 0; i < 100000; i++){
tmp[i] = i * 42;
}
sleep(5);
return 0;
}
I had thought "time" was untrustworthy - but I can't remember why I thought that.
Looks like it uses wait4, which uses getrusage, so it should be o.k. Be aware that wait3/4 count children as well if there are any.
Minor page faults are faults that don't result in physical I/O/ - i.e. they can be resolved from the page cache (usually). These are good page faults - the mm system is working as designed.
Trying to ascertain memory usage under Linux is a can of worms.
Hi Tink,
I'm compiling with g++ version 4.4.1 on Ubuntu 9.10 i686 2.6.31-19.
I've also tried the same thing on my Debian unstable 2.6.18.8, which has g++ 4.4.3.
Using gnome-terminal.
My program compiles fine without the #include <unistd.h>, maybe that is included by default with g++.
But yes, I have been using the full path /usr/bin/time but that does not seem to produce any sensible result like you have.
@syg00
Thanks for clearing up the minor pagefault.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.