process_state
process_state is a lightweight, cross-platform Rust library for tracking, caching, and managing child processes.
It works on both Unix and Windows, making it ideal for build tools, infrastructure management, or any program that launches multiple commands and needs to persist their state.
Features
- Track any command launched from your Rust program.
- Persist process state across sessions.
- Query running or stopped processes.
- Cross-platform (Windows and Unix).
- Easy-to-use API with minimal boilerplate.
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Then run:
Usage
use ;
use Command;
API Overview
ProcessState
new(namespace: &str) -> Result<ProcessState, Error>– Create a new state manager with a namespace.add_process(&mut self, child: &Child, label: &str, command: &str) -> Result<(), Error>– Track a new process.remove_process(&mut self, pid: u32) -> Result<(), Error>– Stop tracking a process.refresh(&mut self) -> Result<(), Error>– Update all tracked processes’ statuses.get_running(&self) -> Vec<&ProcessInfo>– Get currently running processes.get_all(&self) -> Vec<&ProcessInfo>– Get all tracked processes.
ProcessInfo
pid: u32– Process ID.label: String– Label you assigned.command: String– Original command.start_time: SystemTime– Start time.status: ProcessStatus– Current status.
ProcessStatus
RunningStoppedError(String)
License
This project is licensed under MIT OR Apache-2.0.
Contributing
Contributions, bug reports, and feature requests are welcome! Please submit a PR or open an issue on GitHub.