The nix
library does a good job of providing idiomatic rust wrappers around low-level UNIX operations, including sending and handling signals. In this case, you would create a nix::Pid
from child_process.id()
, then pass it to kill
like so:
use nix::unistd::Pid;
use nix::sys::signal::{self, Signal};
// Spawn child process.
let mut child = std::process::Command::new();
/* build rest of command */
child.spawn().unwrap();
// Send SIGTERM to child process.
signal::kill(Pid::from_raw(child.id()), Signal::SIGTERM).unwrap();