| Crates.io | process_state |
| lib.rs | process_state |
| version | 1.0.0 |
| created_at | 2025-11-05 14:45:58.907914+00 |
| updated_at | 2025-11-05 14:45:58.907914+00 |
| description | A Rust library that lets you track, cache, and manage commands like a process manager |
| homepage | https://github.com/m-epasta/process_state |
| repository | https://github.com/m-epasta/process_state |
| max_upload_size | |
| id | 1918104 |
| size | 22,761 |
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.
Add this to your Cargo.toml:
[dependencies]
process_state = "1.0.0"
Then run:
cargo build
use process_state::{ProcessState, ProcessStatus};
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize ProcessState
let mut state = ProcessState::new("myapp")?;
// Spawn a child process
let child = if cfg!(windows) {
Command::new("timeout").arg("5").spawn()?
} else {
Command::new("sleep").arg("5").spawn()?
};
// Track the process
state.add_process(&child, "example", "sleep 5")?;
// Refresh status of all tracked processes
state.refresh()?;
// List running processes
for p in state.get_running() {
println!("{} is running with PID {}", p.label, p.pid);
}
Ok(())
}
ProcessStatenew(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.ProcessInfopid: u32 – Process ID.label: String – Label you assigned.command: String – Original command.start_time: SystemTime – Start time.status: ProcessStatus – Current status.ProcessStatusRunningStoppedError(String)This project is licensed under MIT OR Apache-2.0.
Contributions, bug reports, and feature requests are welcome! Please submit a PR or open an issue on GitHub.