https://github.com/nu11ptr/send_ctrlc
Cross platform crate for sending interrupts/ctrl-c to child processes
https://github.com/nu11ptr/send_ctrlc
Last synced: 3 months ago
JSON representation
Cross platform crate for sending interrupts/ctrl-c to child processes
- Host: GitHub
- URL: https://github.com/nu11ptr/send_ctrlc
- Owner: nu11ptr
- License: mit
- Created: 2025-11-06T22:20:06.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-15T15:35:54.000Z (7 months ago)
- Last Synced: 2025-12-13T14:41:39.557Z (7 months ago)
- Language: Rust
- Size: 32.2 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# send_ctrlc
[](https://crates.io/crates/send_ctrlc)
[](https://docs.rs/send_ctrlc)
[](https://github.com/nu11ptr/send_ctrlc/actions)
[](https://codecov.io/github/nu11ptr/send_ctrlc)
A cross platform crate for interrupting or terminating child processes
## Install
```shell
cargo add send_ctrlc
# Or for async/tokio:
cargo add send_ctrlc -F tokio
```
## Features
* Cross platform (including Windows)
* Uniform cross platform API
* Both sync and async
* Only 2 unsafe calls
* Minimal dependencies:
* Synchronous: `libc` on unix, and `windows-sys` on windows
* Asynchronous: `tokio` (with only `process` feature)
## Examples
> The first example below is for synchronous use cases and the second for tokio/async use cases. However, both `interrupt` and `terminate` are available for both sync/async code.
```rust
use send_ctrlc::{Interruptible as _, InterruptibleCommand as _};
// Interrupt example
#[cfg(not(feature = "tokio"))]
fn main() {
// Create a continuous ping standard command
let mut command = std::process::Command::new("ping");
#[cfg(windows)]
command.arg("-t");
command.arg("127.0.0.1");
// Spawn the ping, interrupt it, and wait for it to complete
let mut child = command.spawn_interruptible().unwrap();
child.interrupt().unwrap();
child.wait().unwrap();
}
// Terminate example (async/tokio)
#[cfg(feature = "tokio")]
#[tokio::main]
async fn main() {
// Create a continuous ping standard command
let mut command = tokio::process::Command::new("ping");
#[cfg(windows)]
command.arg("-t");
command.arg("127.0.0.1");
// Spawn the ping, interrupt it, and wait for it to complete
let mut child = command.spawn_interruptible().unwrap();
child.terminate().unwrap();
child.wait().await.unwrap();
}
```
## Contributions
Contributions are welcome as long they align with the vision for this crate.