Neid has asked for the wisdom of the Perl Monks concerning the following question:

Hi, all.

I would like to estimate process memory usage just like 
gnome-system-monitor does ('Memory' header). I looked into 
monitor source code and I know that it uses libgtop to 
estimate value. I'm unable to find proper formula. 
I think I know the difference between vsize, rss, shared etc.
For example rss-shared gives me different value than that in
monitor.

Thanks!
  • Comment on Estimate process memory usage with GTop

Replies are listed 'Best First'.
Re: Estimate process memory usage with GTop
by zentara (Cardinal) on Apr 11, 2007 at 16:16 UTC
    You might want to look at Proc::ProcessTable. As far as interpreting the values, it's pretty complicated. Google and groups.google search for "linux memoery stats" and read all the fine details about different kernels and the way they report memory usage. For instance, I was testing some c programs, that malloc'd huge memory. Well it never showed up, until I actually used it. It was shown as swap until I actually filled them with values. So it can get pretty complicated with that aspect, and shared library files, etc.
    #!/usr/bin/perl use Proc::ProcessTable; ############################################################# # Dump all the information in the current process table $t = new Proc::ProcessTable; while(1){ foreach $p (@{$t->table}) { print "\n--------------------------------\n"; foreach $f ($t->fields){ print $f, ": ", $p->{$f}, " "; } } sleep(1); }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Estimate process memory usage with GTop
by perrin (Chancellor) on Apr 11, 2007 at 21:19 UTC
    Did you try the GTop module from CPAN? There are examples of using it here.