Crate clonablechild [] [src]

Extends and wraps std::process::Child to make it clonable. Thus eliminating the problem that libstd does not have a cross platfrom and simple way to kill a child while also waiting for it.

Getting Started

Add the dependency to your Cargo.toml:

clonablechild = "0.1"


Use it in your program to kill a sleep process before it terminates naturally:

extern crate clonablechild;

use clonablechild::{ChildExt, ClonableChild};

use std::process::Command;
use std::thread;
use std::time::Duration;

fn main() {
    // This command is specific to unix systems. See tests for Windows examples.
    let child = Command::new("sleep").arg("10").spawn().unwrap();
    let clonable_child = child.into_clonable();

    let exit_status = clonable_child.wait().unwrap();

    // Assert child was killed by a signal and did not exit cleanly
    assert_eq!(None, exit_status.code());

fn kill_async(child: ClonableChild) {
    thread::spawn(move || {
        thread::sleep(Duration::new(1, 0));
        child.kill().expect("Expected to be able to kill subprocess");



Representation of a clonable std::process::Child.



A trait that extends Child with a method to convert it into a ClonableChild.