Perl – Universal way to get memory usage of a process

Hi,

I work on Mac and well most of the tools we have was developed for Linux platform. When we want to check the memory usage of a process, we often use a module that directly read in “/proc”, opening a file there… That doesn’t work on any other platform than the one with procfs. That exclude Windows, Mac, and many others I suppose.

So thanks to Proc::ProcessTable module, we can do something fine on all platform.

Let me show a “get_current_process_memory” method :

This method process the process table of the system and return object for all process. So I index it by pid, and then return the “rss” to get the resident memory of my current process.

Enjoy !

Celogeek

Special Thanks to leont on IRC at Web-Simple

Short URL: http://sck.pm/7jW

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">