Skip to content

Instantly share code, notes, and snippets.

@bpot
Created March 6, 2015 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpot/db82b1eb2700e9287227 to your computer and use it in GitHub Desktop.
Save bpot/db82b1eb2700e9287227 to your computer and use it in GitHub Desktop.
Freezing MRI with FFI
require 'ffi'
module Block
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :sleep, [:uint], :void
end
Thread.new {
sleep 10
puts "About to block the process"
Block.sleep 3600
}
loop do
puts "#{Time.now}: We are still alive!"
sleep 1
end
2015-03-05 17:54:27 -0800: We are still alive!
2015-03-05 17:54:28 -0800: We are still alive!
2015-03-05 17:54:29 -0800: We are still alive!
2015-03-05 17:54:30 -0800: We are still alive!
2015-03-05 17:54:31 -0800: We are still alive!
2015-03-05 17:54:32 -0800: We are still alive!
2015-03-05 17:54:33 -0800: We are still alive!
2015-03-05 17:54:34 -0800: We are still alive!
2015-03-05 17:54:35 -0800: We are still alive!
2015-03-05 17:54:36 -0800: We are still alive!
About to block the process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment