Bringing common kernel APIs into Ruby using FFI.



irb(main):001:0> require 'ktools'
=> true
irb(main):002:0> r, w = IO.pipe
=> [#<IO:0x4fa90c>, #<IO:0x4fa880>]
irb(main):003:0> kq = Kqueue.new
=> #<Kernel::Kqueue:0x4f43a4 @kqfd=6, @fds={}>
irb(main):004:0> kq.add(:socket, r, :events => [:read, :write])
=> true
irb(main):005:0> kq.poll
=> []
irb(main):006:0> w.write "foo"
=> 3
irb(main):007:0> kq.poll
=> [{:type=>:socket, :target=>#<IO:0x4fa90c>, :events=>[:read]}]
irb(main):008:0> [r, w, kq].each {|i| i.close}


I plan to support the following kernel APIs:

  • kqueue (works - see tests/test_kqueue.rb)

  • epoll (works - see tests/test_epoll.rb)

  • inotify

  • netlink

and maybe some others! I will at first hook up the C interfaces as directly as possible, and then write Rubyist-friendly wrappers around them.

Currently kqueue and epoll have Ruby wrapper APIs.


  1. git clone git://github.com/yakischloba/ktools.git

  2. cd ktools

  3. gem build ktools.gemspec

  4. sudo gem install ktools-x.x.x.gem

Also gems are on Rubyforge, so you can simply 'sudo gem install ktools', but commits will be frequent for some time, so you'll probably want to be pulling the latest from Github.


  • Documentation is located at ktools.rubyforge.org

  • Familiarity with the actual kernel subsystems is helpful for nitty-gritty usage or debugging issues.


Please file all issues on the Github issue tracker. Patches (with tests) are welcome and encouraged, as are suggestions about API design, etc. It's all up in the air right now.

  • yakischloba on freenode

  • jakecdouglas at gmail