#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

6 releases

Uses old Rust 2015

0.2.0 Nov 23, 2018
0.1.5 Mar 7, 2017
0.1.4 Feb 10, 2017
0.1.3 Feb 21, 2016
0.1.0 Sep 8, 2015

#61 in Operating systems

Download history 400929/week @ 2024-06-11 364467/week @ 2024-06-18 386998/week @ 2024-06-25 388819/week @ 2024-07-02 425064/week @ 2024-07-09 439178/week @ 2024-07-16 460234/week @ 2024-07-23 439828/week @ 2024-07-30 458239/week @ 2024-08-06 482681/week @ 2024-08-13 497502/week @ 2024-08-20 466640/week @ 2024-08-27 513382/week @ 2024-09-03 487045/week @ 2024-09-10 452877/week @ 2024-09-17 415950/week @ 2024-09-24

1,934,028 downloads per month
Used in 1,513 crates (67 directly)

MIT/Apache

18KB
263 lines

wait-timeout

Build Status 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