#timeout #windows #unix #child #process #wait

bin+lib wait-timeout

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

6 releases

0.1.5 Mar 7, 2017
0.1.4 Feb 10, 2017
0.1.3 Feb 21, 2016
0.1.2 Jan 31, 2016
0.1.0 Sep 8, 2015

#15 in Operating systems

Download history 656/week @ 2018-07-22 1132/week @ 2018-07-29 959/week @ 2018-08-05 855/week @ 2018-08-12 893/week @ 2018-08-19 1032/week @ 2018-08-26 1125/week @ 2018-09-02 1200/week @ 2018-09-09 1051/week @ 2018-09-16 1205/week @ 2018-09-23 1737/week @ 2018-09-30 5522/week @ 2018-10-07 6997/week @ 2018-10-14

1,186 downloads per month
Used in 11 crates (9 directly)

MIT/Apache

20KB
330 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"

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 registeres a SIGCHLD handler and initializes some global state. 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

~165KB