pub fn kill_tree_with_config(
process_id: ProcessId,
config: &Config,
) -> Result<Outputs>Expand description
Kills the target process and all of its children recursively using the given Config.
§Platform-specifics
§Windows
Internally, TerminateProcess from Win32 is used.
§Linux, Macos
Internally, kill from libc is used.
§Examples
Kill processes using the SIGKILL signal.
use kill_tree::{
blocking::kill_tree_with_config, get_available_max_process_id, Config, Result,
};
fn main() -> Result<()> {
let target_process_id = get_available_max_process_id(); // Replace with your target process ID.
let config = Config {
signal: String::from("SIGKILL"),
..Default::default()
};
let _ = kill_tree_with_config(target_process_id, &config)?;
Ok(())
}Kills all children except the target process.
use kill_tree::{
blocking::kill_tree_with_config, get_available_max_process_id, Config, Result,
};
fn main() -> Result<()> {
let target_process_id = get_available_max_process_id(); // Replace with your target process ID.
let config = Config {
include_target: false,
..Default::default()
};
let _ = kill_tree_with_config(target_process_id, &config)?;
Ok(())
}§Errors
§InvalidProcessId
Returns the process ID of the kernel or system, or if greater than the available maximum process ID.
§InvalidCast
Returned internally when an invalid type conversion occurs during a system API call.
This is an error that should not occur under normal circumstances.
§InvalidProcEntry
Returned when inquiry, or parsing within the Linux /proc/ path fails.
§Io
Returned when access within the Linux /proc/ path fails.
§Windows
Returned when the Win32 API used internally fails.
§Unix
Returned when the libc API used internally fails.