4 releases (2 breaking)

0.3.0 Dec 5, 2021
0.2.0 Feb 15, 2021
0.1.1 Sep 24, 2019
0.1.0 Sep 23, 2019

#1043 in Asynchronous

Download history 6/week @ 2024-02-19 22/week @ 2024-02-26 3/week @ 2024-03-04 2/week @ 2024-03-11 76/week @ 2024-04-01

79 downloads per month

MIT license

14KB
207 lines

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, Events, Token, Ready, PollOpt};
use std::process::{Command, Child};

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

poll.register(&pidfd, Token(0), Ready::readable(), PollOpt::edge())
             .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

Dependencies

~0.3–10MB
~63K SLoC