An FFI wrapper for kqueue
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 27 commits behind mat813:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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: