| Crates.io | send_ctrlc |
| lib.rs | send_ctrlc |
| version | 0.6.0 |
| created_at | 2025-11-07 00:46:15.687649+00 |
| updated_at | 2025-11-15 15:36:05.554262+00 |
| description | A cross platform crate for sending ctrl-c to child processes |
| homepage | |
| repository | https://github.com/nu11ptr/send_ctrlc |
| max_upload_size | |
| id | 1920912 |
| size | 20,810 |
A cross platform crate for interrupting or terminating child processes
cargo add send_ctrlc
# Or for async/tokio:
cargo add send_ctrlc -F tokio
libc on unix, and windows-sys on windowstokio (with only process feature)The first example below is for synchronous use cases and the second for tokio/async use cases. However, both
interruptandterminateare available for both sync/async code.
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 are welcome as long they align with the vision for this crate.