Today I Learned

A Hashrocket project

The memory your Ruby process is taking

Today I learned how to get the memory taken by a Ruby process from inside a Ruby code:

def mem
  `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split[1] + ' KB'
end
mem
# => "61772 KB"

By the way in Ruby $$ is the same as Process.pid.

Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.