[][src]Struct process_control::Terminator

pub struct Terminator(_);

A wrapper that stores enough information to terminate a process.

Instances can only be constructed using ChildExt::terminator.

Implementations

impl Terminator[src]

pub unsafe fn terminate(&self) -> Result<()>[src]

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

impl Debug for Terminator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.