LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
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;
}

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, 03:44 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

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
    Code:
    $ /usr/bin/time -f "%M"  ./foo
    28496


Cheers,
Tink
 
Old 03-06-2010, 05:34 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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-06-2010, 11:54 PM   #4
simitra
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 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.

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


Reply



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 08:33 AM
running /usr/bin/groups <super user> returns void Ron_09 Linux - Enterprise 4 09-15-2009 07:48 AM
Failed to chck remot comnd executin using shells /usr/bin/ssh and /usr/bin/rsh farnaw4u Linux - Software 2 04-06-2009 12:08 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04: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 01:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:41 PM.

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