#child-process #timeout #wait #waiting

bin+lib wait-timeout

A crate to wait on a child process with a timeout specified across Unix and Windows platforms

7 releases

Uses old Rust 2015

0.2.1 Feb 3, 2025
0.2.0 Nov 23, 2018
0.1.5 Mar 7, 2017
0.1.4 Feb 10, 2017
0.1.0 Sep 8, 2015

#20 in Operating systems

Download history 578129/week @ 2024-10-21 563495/week @ 2024-10-28 561432/week @ 2024-11-04 559474/week @ 2024-11-11 542145/week @ 2024-11-18 474682/week @ 2024-11-25 536873/week @ 2024-12-02 668569/week @ 2024-12-09 614145/week @ 2024-12-16 272557/week @ 2024-12-23 389051/week @ 2024-12-30 712975/week @ 2025-01-06 808935/week @ 2025-01-13 736444/week @ 2025-01-20 830574/week @ 2025-01-27 880807/week @ 2025-02-03

3,302,237 downloads per month
Used in 1,671 crates (77 directly)

MIT/Apache

17KB
242 lines

wait-timeout

Build Status

Documentation

Rust crate for waiting on a Child process with a timeout specified.

# Cargo.toml
[dependencies]
wait-timeout = "0.1.5"

lib.rs:

A crate to wait on a child process with a particular timeout.

This crate is an implementation for Unix and Windows of the ability to wait on a child process with a timeout specified. On Windows the implementation is fairly trivial as it's just a call to WaitForSingleObject with a timeout argument, but on Unix the implementation is much more involved. The current implementation registers a SIGCHLD handler and initializes some global state. This handler also works within multi-threaded environments. If your application is otherwise handling SIGCHLD then bugs may arise.

Example

use std::process::Command;
use wait_timeout::ChildExt;
use std::time::Duration;

let mut child = Command::new("foo").spawn().unwrap();

let one_sec = Duration::from_secs(1);
let status_code = match child.wait_timeout(one_sec).unwrap() {
    Some(status) => status.code(),
    None => {
        // child hasn't exited yet
        child.kill().unwrap();
        child.wait().unwrap().code()
    }
};

Dependencies

~43KB