Getting memory from my process from OSX using Ruby

I have a Ruby application that (on Linux) uses the / proc file system to get memory usage information. 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 am looking for a system call, I do not want to start a process for this (sorry Lars!).

+11
ruby macos
Nov 09 '10 at 11:03
source share
3 answers

Referring to this answer , it seems to you that you need to call proc_pidinfo() . I don't think there is a Ruby equivalent, so you have to write a C-extension or use the ruby-ffi gem.

Other sources indicate that Ruby 1.9.2 comes with built-in FFI, but this version does not come with OS X.

+3
Nov 10 2018-10-10
source share

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

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

Tested to work on both Linux and OS X.

This returns the number of bytes in which the process is in memory, with the exception of those unloaded

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

 memory_usage = `ps -o vsz= -p #{Process.pid}`.to_i # in kilobytes 
+21
Nov 09 '10 at 12:29
source share

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

0
Sep 14 '12 at 4:40
source share



All Articles