Expand description
§PID Set Library
pid_set
is a library for managing and monitoring process identifiers (PIDs) using epoll on Linux.
It allows for asynchronous notification when a process exits by leveraging epoll and pidfd (process file descriptors).
§Features
- Create a
PidSet
to manage multiple PIDs. - Monitor process exits using epoll.
- Handle system call errors gracefully with custom errors.
§Usage
Add this to your Cargo.toml
:
[dependencies]
pid_set = "0.1.0"
§Examples
Here’s how you can use PidSet
to monitor a list of PIDs:
use pid_set::{PidSet, PidSetError};
fn main() -> Result<(), PidSetError> {
let mut cmd1 = std::process::Command::new("sleep");
cmd1.arg("0.1");
let mut cmd2 = std::process::Command::new("sleep");
cmd2.arg("0.2");
let pids = vec![cmd1.spawn().unwrap().id(), cmd2.spawn().unwrap().id()]; // Example PIDs
let mut pid_set = PidSet::new(pids);
// Wait for any PID to exit
pid_set.wait_any()?;
// Clean up
pid_set.close()?;
Ok(())
}
Structs§
- PidSet
- Manages a set of PIDs and their corresponding epoll file descriptors.
Enums§
- PidSet
Error - Errors that can occur in the
PidSet
.