Get Process Memory
Do you need to get the memory usage of a process? Great because this library does that.
Install
In your Gemfile
add
gem 'get_process_mem'
then run $ bundle install
.
If you're using Windows you'll also need to have the sys-proctable
gem.
Use It
Get the current process memory usage:
mem = GetProcessMem.new
puts mem.inspect
#<GetProcessMem @mb=24.28125 @gb=0.023712158203125 @kb=24864.0 @bytes=25460736 >
mem.bytes
mem.kb
mem.mb
mem.gb
Note: All numeric values returned as a float except bytes which is an integer.
Get memory usage of another process:
`echo 'nothing to see here' > tmplogf`
pid = Process.spawn('tail -f tmplog')
mem = GetProcessMem.new(pid)
puts mem.inspect
Process.kill('TERM', pid)
Process.wait(pid)
mem.inspect
`rm tmplog`
On Linux, for memory size we return the RSS or the Resident Set Size, basically how much memory the program takes up in RAM at the time, including all the shared memory.
License
MIT