Perl – Universal way to get memory usage of a process


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 !


Special Thanks to leont on IRC at Web-Simple

Short URL: