https://github.com/faern/clonablechild
Makes std::process::Child clonable, so it becomes possible to both wait and kill a subprocess
https://github.com/faern/clonablechild
Last synced: 9 months ago
JSON representation
Makes std::process::Child clonable, so it becomes possible to both wait and kill a subprocess
- Host: GitHub
- URL: https://github.com/faern/clonablechild
- Owner: faern
- License: apache-2.0
- Created: 2016-12-23T00:22:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-17T15:08:57.000Z (about 9 years ago)
- Last Synced: 2024-10-17T15:44:21.541Z (over 1 year ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# ClonableChild
**DEPRECATED**: *This crate has been deprecated and yanked from crates.io. The problem it solves is solved in a better way by the [`shared_child`](https://crates.io/crates/shared_child) crate. See [this issue](https://github.com/oconnor663/shared_child.rs/issues/9) for more information.*
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:
```toml
[dependencies]
clonablechild = "0.1"
```
## Example
Use it in your program to kill a sleep process before it terminates naturally:
```rust
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();
kill_async(clonable_child.clone());
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());
assert!(!exit_status.success());
}
fn kill_async(child: ClonableChild) {
thread::spawn(move || {
thread::sleep(Duration::new(1, 0));
child.kill().expect("Expected to be able to kill subprocess");
});
}
```