Skip to main content

run_with_timeout

Function run_with_timeout 

Source
pub fn run_with_timeout(
    command: &str,
    args: &[&str],
    timeout: Duration,
    config: TimeoutConfig,
) -> SysprimsResult<TimeoutOutcome>
Expand description

Run a command with timeout.

Spawns the command and waits for it to complete or timeout. If the command times out, the acquired process group or Job is signaled (when using GroupByDefault). Cooperative descendants in that containment are targeted; Unix descendants can still leave a process group later.

§Arguments

  • command - Command to execute (path or name in PATH)
  • args - Command arguments
  • timeout - Maximum duration to wait for command completion
  • config - Timeout configuration (signal, escalation, grouping)

§Returns

  • Ok(TimeoutOutcome::Completed { .. }) - Command finished within timeout
  • Ok(TimeoutOutcome::TimedOut { .. }) - Command was killed due to timeout
  • Err(SysprimsError) - Failed to spawn or fatal error

§Examples

use std::time::Duration;
use sysprims_timeout::{run_with_timeout, TimeoutConfig};

// Replaces: timeout 300s make build
let result = run_with_timeout(
    "make",
    &["build"],
    Duration::from_secs(300),
    TimeoutConfig::default(),
);