Struct process_control::Terminator[][src]

pub struct Terminator(_);
Expand description

A wrapper that stores enough information to terminate a process.

Instances can only be constructed using ChildExt::terminator.

Implementations

Terminates a process as immediately as the operating system allows.

Behavior should be equivalent to calling Child::kill for the same process. However, this method does not require a reference of any kind to the Child instance of the process, meaning that it can be called even in some unsafe circumstances.

Safety

If the process is no longer running, a different process may be terminated on some operating systems. Reuse of process identifiers makes it impossible for this method to determine if the intended process still exists.

Thus, this method should not be used in production code, as Child::kill more safely provides the same functionality. It is only used for testing in this crate and may be used similarly in others.

Examples

use std::path::Path;
use std::process::Command;
use std::thread;

use process_control::ChildExt;

let dir = Path::new("hello");
let mut process = Command::new("mkdir").arg(dir).spawn()?;
let terminator = process.terminator()?;

let thread = thread::spawn(move || process.wait());
if !dir.exists() {
    // [process.kill] requires a mutable reference.
    unsafe { terminator.terminate()? }
}

let exit_status = thread.join().expect("thread panicked")?;
println!("exited {}", exit_status);

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.