Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An FFI wrapper for kqueue

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .yardopts
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 rb-kqueue.gemspec


This is a simple wrapper over the kqueue BSD event notification interface (supported on FreeBSD, NetBSD, OpenBSD, and Darwin). It uses the FFI gem to avoid having to compile a C extension.

API documentation is available on


This code is incomplete, and didn't work last I had a chance to test it. I don't have time to continue working on it at the moment, so I'm posting it online for posterity and in case anyone wants to take a crack at it.

If anyone wants commit rights, just email me at


The API is similar to the kqueue C API, but with a more Rubyish feel. First, create a queue:

queue =

Then, tell it to watch the events you're interested in:

queue.watch_file("path/to/foo.txt", :write) {puts "foo.txt was modified!"}
queue.watch_process(, :fork, :exec) do |event|
  puts "This process has #{ {|f| f.to_s + "ed"}.join(" and ")}"

KQueue can monitor for all sorts of events. For a full list, see the watch_* methods on {Queue}.

Finally, run the queue:

This will loop infinitely, calling the appropriate callbacks when the events are fired. If you don't want infinite looping, you can also block until there are available events, process them all at once, and then continue on your merry way:

Something went wrong with that request. Please try again.