Skip to content

Instantly share code, notes, and snippets.

@mekanix
Created November 22, 2025 23:56
Show Gist options
  • Select an option

  • Save mekanix/12f5d4a54e08146c49a0c9e0d31dad37 to your computer and use it in GitHub Desktop.

Select an option

Save mekanix/12f5d4a54e08146c49a0c9e0d31dad37 to your computer and use it in GitHub Desktop.
use kqueue;
use std::{fs::File, os::fd::AsRawFd};
fn main() {
let f = File::open("/bin/sh").expect("Opening file failed");
let mut watcher = kqueue::Watcher::new().expect("Failed to create kqueue watcher");
watcher.add_fd(f.as_raw_fd(), kqueue::EventFilter::EVFILT_READ, kqueue::FilterFlag::NOTE_READ).expect("Failed to add file to watcher");
watcher.watch().expect("Failed to watch for events");
for i in watcher.iter() {
println!("Hello, world! {:?}!", i);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment