Expand description
Subprocess execution with explicit I/O modes, process-group isolation, and timeouts.
This crate provides functionality to execute external processes with:
- Timeout support with configurable grace period
- SIGTERM → SIGKILL escalation for graceful shutdown
- Process group isolation to ensure child processes are properly terminated
- Explicit captured, observed, and inherited stdio modes
- Environment variable control
- Working directory configuration
§I/O modes
ProcessIo::Captured captures stdout and stderr separately through pipes.
It is deterministic for non-interactive commands, but it is not a terminal
and cannot guarantee exact ordering between stdout and stderr.
ProcessIo::Observed also uses separate pipes and supports live raw-byte
or line callbacks with optional capture. Line observers split deterministically on \n, \r,
and \r\n; invalid UTF-8 is reported lossily.
ProcessIo::Inherited gives the child the parent stdio handles.
This is the right mode for normal terminal commands,
but it does not provide structured output capture.
§Example
use rskit_process::{ProcessConfig, ProcessSpec, run_with_cancel};
use std::time::Duration;
use tokio_util::sync::CancellationToken;
let spec = ProcessSpec::new("echo")
.arg("hello")
.arg("world");
let config = ProcessConfig::default().with_timeout(Some(Duration::from_secs(30)));
let result = run_with_cancel(&spec, &config, CancellationToken::new()).await?;
println!("stdout: {}", result.stdout);
println!("exit code: {:?}", result.exit_code);Structs§
- AppError
- Re-export error types Application-level structured error.
- ArgRedaction
- Redaction policy for command-line arguments emitted in process spawn logs.
- Captured
Io - Pipe-backed deterministic capture mode.
- Inherited
Io - Inherited terminal stdio mode.
- Observed
Io - Pipe-backed live observation mode with optional capture.
- Output
Observer - Optional callbacks for line-oriented process output.
- Output
Policy - Output capture policy for pipe-backed modes.
- Persistent
Config - Configuration for a persistent process.
- Persistent
Output - Persistent process output forwarding policy.
- Persistent
Output Observer - Byte observers for persistent process output.
- Persistent
Process - Running persistent process.
- Persistent
Run - Result of starting a persistent process.
- Persistent
Startup - Captured output retained while waiting for persistent readiness.
- Process
Config - Configuration for subprocess execution behavior.
- Process
Result - Result of a completed subprocess execution.
- Process
Spec - What to execute as a subprocess.
- PtyIo
- Pseudoterminal-backed I/O mode.
- PtySize
- Window size of a pseudoterminal, in character cells plus optional pixels.
- Signal
Policy - Signal and process-tree termination policy.
Enums§
- EnvPolicy
- Command environment policy.
- Error
Code - Re-export error types Machine-readable error code.
- Input
Policy - Standard input policy.
- Persistent
Output Stream - Parent stream used for forwarding persistent output.
- Persistent
Readiness - Persistent process readiness policy.
- Persistent
Start Error Kind - Machine-readable persistent process startup failure classification.
- Process
Io - Process I/O strategy.
- Shutdown
Outcome - Outcome of requesting persistent process shutdown.
Constants§
- DEFAULT_
MAX_ OUTPUT_ BYTES - Default maximum retained bytes for each captured output stream.
Functions§
- command
- Create a subprocess specification.
- interrupt_
process_ group - Request graceful interruption for the process group led by the provided child PID.
- isolate_
process_ group - Configure a command so the spawned child becomes the leader of a new process group.
- kill_
process_ group - Forcefully terminate the process group led by the provided child PID.
- persistent_
start_ error_ kind - Return the structured persistent startup error kind attached to an
AppError. - run
- Execute a subprocess on the current thread using captured or inherited I/O mode.
- run_
with_ cancel - Execute a subprocess with the given configuration and cancellation token.
- start_
persistent_ with_ cancel - Start a persistent process and wait for its readiness policy.
- terminal_
size - Query the window size of the terminal backing
fd. - terminate_
process_ group - Request graceful termination for the process group led by the provided child PID.
Type Aliases§
- AppResult
- Re-export error types Convenience alias used throughout rskit crates.