Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 03-05-2010, 09:55 PM   #1
LQ Newbie
Registered: Mar 2010
Posts: 3

Rep: Reputation: 0
Using /usr/bin/time always returns 0 when getting maximum resident memory

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

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;
return 0;

a run with `time ./foo` gives

1.05user 0.02system 0:01.10elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+10030minor)pagefaults 0swaps

The minor page-fault is suspicious, does that mean memory is being used.. but not recorded? if so, how can I know how much memory is being mapped?
Old 03-06-2010, 04:44 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913

Welcome to LQ!

Which version of Linux and which compiler are you using?
What's your shell?

There are several 'odd' things about your example.
  1. It won't compile w/o atting '#include <unistd.h>'
  2. your output for time gives the binaries output even though, as you call it w/o the full path, it should be overridden by the bash built-in
  3. compiled and run on my system (with full path, /usr/bin/time -f "%M" ./foo does produce sensible output
    $ /usr/bin/time -f "%M"  ./foo

Old 03-06-2010, 06:34 PM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,484

Rep: Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097Reputation: 3097
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.
Old 03-07-2010, 12:54 AM   #4
LQ Newbie
Registered: Mar 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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, 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.

Thanks for clearing up the minor pagefault.

Last edited by simitra; 03-07-2010 at 01:22 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 09:33 AM
running /usr/bin/groups <super user> returns void Ron_09 Linux - Enterprise 4 09-15-2009 08:48 AM
Failed to chck remot comnd executin using shells /usr/bin/ssh and /usr/bin/rsh farnaw4u Linux - Software 2 04-06-2009 01:08 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 05:05 AM
path in services wrong for clamav updated frm 0.75 to 0.80 usr/bin vs usr/local/bin Emmanuel_uk Linux - Newbie 3 04-22-2005 02:02 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration