pub struct Child { /* private fields */ }Expand description
A wrapper around smol::process::Child that ensures all subprocesses
are killed when the process is terminated: on Unix by using process
groups, and on Windows by using job objects.
On Windows, dropping this struct closes the job object handle, which terminates all processes in the job. This also applies when the Open GPUI process exits for any reason, since the OS closes its handles, so spawned process trees can never outlive their owner.
Implementations§
Methods from Deref<Target = Child>§
Sourcepub fn id(&self) -> u32
pub fn id(&self) -> u32
Returns the OS-assigned process identifier associated with this child.
§Examples
use async_process::Command;
let mut child = Command::new("ls").spawn()?;
println!("id: {}", child.id());Sourcepub fn kill(&mut self) -> Result<(), Error>
pub fn kill(&mut self) -> Result<(), Error>
Forces the child process to exit.
If the child has already exited, an InvalidInput error is returned.
This is equivalent to sending a SIGKILL on Unix platforms.
§Examples
use async_process::Command;
let mut child = Command::new("yes").spawn()?;
child.kill()?;
println!("exit status: {}", child.status().await?);Sourcepub fn try_status(&mut self) -> Result<Option<ExitStatus>, Error>
pub fn try_status(&mut self) -> Result<Option<ExitStatus>, Error>
Returns the exit status if the process has exited.
Unlike status(), this method will not drop the stdin handle.
§Examples
use async_process::Command;
let mut child = Command::new("ls").spawn()?;
match child.try_status()? {
None => println!("still running"),
Some(status) => println!("exited with: {}", status),
}Sourcepub fn status(&mut self) -> impl Future<Output = Result<ExitStatus, Error>>
pub fn status(&mut self) -> impl Future<Output = Result<ExitStatus, Error>>
Drops the stdin handle and waits for the process to exit.
Closing the stdin of the process helps avoid deadlocks. It ensures that the process does not block waiting for input from the parent process while the parent waits for the child to exit.
§Examples
use async_process::{Command, Stdio};
let mut child = Command::new("cp")
.arg("a.txt")
.arg("b.txt")
.spawn()?;
println!("exit status: {}", child.status().await?);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Child
impl RefUnwindSafe for Child
impl Send for Child
impl Sync for Child
impl Unpin for Child
impl UnsafeUnpin for Child
impl UnwindSafe for Child
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more