pub struct Child {
pub seccomp_notif: Option<SeccompNotif>,
pub stdin: Option<ChildStdin>,
pub stdout: Option<ChildStdout>,
pub stderr: Option<ChildStderr>,
/* private fields */
}Expand description
Represents a child process.
NOTE: The child process is not killed or waited on when Child is dropped.
If Child is not waited on before dropped, the child will continue to run in
the background and may become a “zombie” after the parent exits. It is
therefore best practice to always wait on child processes.
Fields§
§seccomp_notif: Option<SeccompNotif>A handle to the seccomp notifier, if requested. This must be consumed or dropped for the child to be able to exit.
stdin: Option<ChildStdin>The handle for writing to the child’s standard input (stdin), if it has been captured.
stdout: Option<ChildStdout>The handle for reading from the child’s standard output (stdout), if it has been captured.
stderr: Option<ChildStderr>The handle for reading from the child’s standard error (stderr), if it has been captured.
Implementations§
Source§impl Child
impl Child
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
Attempts to collect the exit status of the child if it has already exited.
Sourcepub async fn wait(&mut self) -> Result<ExitStatus>
pub async fn wait(&mut self) -> Result<ExitStatus>
Waits for the child to exit completely, returning its exit status. This function will continue to return the same exit status after the child process has fully exited.
To avoid deadlocks, the child’s stdin handle, if any, will be closed
before waiting. Otherwise, the child could block waiting for input from
the parent while the parent is waiting for the child. To keep the stdin
handle open and control it explicitly, the caller can .take() it before
calling .wait().
Sourcepub fn wait_blocking(&mut self) -> Result<ExitStatus>
pub fn wait_blocking(&mut self) -> Result<ExitStatus>
Blocks until the child process exits.
Sourcepub async fn wait_with_output(self) -> Result<Output>
pub async fn wait_with_output(self) -> Result<Output>
Simultaneously waits for the child to exit and collect all remaining
output on the stdout/stderr handles, returning an Output instance.
To avoid deadlocks, the child’s stdin handle, if any, will be closed before waiting. Otherwise, the child could block waiting for input from the parent while the parent is waiting for the child.
By default, stdin, stdout and stderr are inherited from the parent. In
order to capture the output into this Result<Output> it is necessary to
create new pipes between parent and child. Use stdout(Stdio::piped())
or stderr(Stdio::piped()), respectively.