bin/occupy-ram

19 lines
385 B
Ruby
Executable file

#!/usr/bin/env ruby
def free_pages
`vm_stat`.split(/\n/).grep(/free/).first.scan(/\d+/).first.to_i
end
mega = 1024 * 1024.0
a = []
n = 0
free = free_pages
until free < 100_000
a << '-' * (100 * mega)
n += 100
free = free_pages
puts "Occupied #{n} MB, #{(4096 * free / mega).round(2)} MB still free"
end
puts 'full, looping forever...'
a.each { |s| s =~ /foo/ } while true