[−][src]Struct process_control::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
Auto Trait Implementations
impl RefUnwindSafe for Terminator
[src]
impl Send for Terminator
[src]
impl Sync for Terminator
[src]
impl Unpin for Terminator
[src]
impl UnwindSafe for Terminator
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,