Crate mio_pidfd[][src]

Expand description

mio-pidfd

mio-pidfd

A Linux pidfd wrapper for mio. This is useful for using mio to wait for multiple child processes to exit in a non-blocking event-driven way.

Heavily inspired by mio-timerfd

Example

use mio_pidfd::PidFd;
use mio::{Poll, Interest, Events, Token};
use std::process::{Command, Child};

let mut poll = Poll::new().unwrap();
let mut events = Events::with_capacity(1024);
let mut child = Command::new("/bin/sleep").arg("1").spawn().unwrap();
let mut pidfd = PidFd::new(&child).unwrap();

poll.registry()
    .register(&mut pidfd, Token(0), Interest::READABLE)
    .unwrap();

poll.poll(&mut events, None).unwrap();
assert!(child.try_wait().unwrap().unwrap().code().unwrap() == 0);

Requirements

This library relies on the pidfd_open() system call which was introduced in Linux kernel version 5.3. The pidfd_send_signal() system call (used by supplementary kill() functionality) was introduced in Linux kernel version 5.1

Structs

A Linux pidfd abstraction that can be used to poll the exit status of multiple child processes using mio.