Warning
This post was published 52 days ago. The information described in this article may have changed.
I'm trying to run a child process in Unix system like this:
Command::new("sh")
.arg("-c")
.arg(command)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to spawn command")
What happens is I need to catch the return type of this call and use .wait()
or .wait_with_output()
It seems like it waits until the process is zombie or terminated, but it's always zombie, I tried to run a simple Python code as the comment & it seems like Rust hold the process zombie,
So I tried to detach the process like this:
unsafe {
Command::new("sh")
.arg("-c")
.arg(command)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.pre_exec(|| {
#[cfg(unix)]
{
libc::setsid();
}
Ok(())
})
.spawn()
.expect("Failed to spawn command")
}
But it seems like Rust still hold the child process captive as zombie,
I would like to let my child process terminated and catch on terminated only because I can manually in runtime change the status of the child process status to zombie for debug purposes and I don't want my Rust runtime to end (You can't differentiate between zombie status of ended run or manually triggered by the user)
Any clues how can I achieve that?
2 posts - 2 participants
🏷️ rust_feed