Getting memory usage of my process from OSX using Ruby

后端 未结 3 496
星月不相逢
星月不相逢 2021-02-03 10:49

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

3条回答
  •  礼貌的吻别
    2021-02-03 11:49

    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 
    

提交回复
热议问题