Alex Rivera | Logout

Getting memory usage of my process from OSX using Ruby

Asked 2010-11-09T11:03:26.833
13

I have a Ruby app which (on Linux) uses the /proc filesystem to get information on its memory usage. Does anyone know how to get the same information for Mac OSX? The task_info system call looks promising but is there an equivalent available from Ruby?

To be clear, I'm looking for a system call, I don't want to kick off a process for this (sorry Lars!).

Edit
Report

2 Answers

24

Taken from http://laurelfan.com/2008/1/15/ruby-memory-usage:

memory_usage = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes 

Verified to work in both Linux and OS X.

This returns the number of bytes that the process has resident in memory, excluding any that are swapped out

To get the total virtual memory size including swap, change rss to vsz (tested in Linux, but not tested in OSX):

memory_usage = `ps -o vsz= -p #{Process.pid}`.to_i # in kilobytes 
answered 2010-11-09T12:29:50.607
1

The OS gem has an rss_bytes method that works for Linux/windows/OS X ...

answered 2012-09-14T04:40:23.150

Your Answer