Trait ChildExt
pub trait ChildExt
Required Methods
fn send_signal(&self, signal: i32) -> Result<()>Sends a signal to a child process.
Errors
This function will return an error if the signal is invalid. The integer values associated with signals are implementation-specific, so it's encouraged to use a crate that provides posix bindings.
Examples
#![feature(unix_send_signal)] use std::{io, os::unix::process::ChildExt, process::{Command, Stdio}}; use libc::SIGTERM; fn main() -> io::Result<()> { # if cfg!(not(all(target_vendor = "apple", not(target_os = "macos")))) { let child = Command::new("cat").stdin(Stdio::piped()).spawn()?; child.send_signal(SIGTERM)?; # } Ok(()) }fn send_process_group_signal(&self, signal: i32) -> Result<()>Sends a signal to a child process's process group.
Errors
This function will return an error if the signal is invalid or if the child process does not have a process group. The integer values associated with signals are implementation-specific, so it's encouraged to use a crate that provides posix bindings.
Examples
#![feature(unix_send_signal)] use std::{io, os::unix::process::{ChildExt, CommandExt}, process::{Command, Stdio}}; use libc::SIGTERM; fn main() -> io::Result<()> { # if cfg!(not(all(target_vendor = "apple", not(target_os = "macos")))) { let child = Command::new("cat") .stdin(Stdio::piped()) .process_group(0) .spawn()?; child.send_process_group_signal(SIGTERM)?; # } Ok(()) }fn kill_process_group(&mut self) -> Result<()>Forces the child process's process group to exit.
This is analogous to
Child::killbut applies to every process in the child process's process group.Use
CommandExt::process_groupto assign a child process to an existing process group, or to make it the leader of a new process group. By default spawned processes are in the parent's process group.Examples
#![feature(unix_kill_process_group)] use std::{os::unix::process::{ChildExt, CommandExt}, process::{Command, Stdio}}; fn main() -> std::io::Result<()> { let mut child = Command::new("cat") .stdin(Stdio::piped()) .process_group(0) .spawn()?; child.kill_process_group()?; Ok(()) }