A small Iron project calls a Command
in some route and returns a Response
. Here is the relevant code of the route handler function:
fn convert(req: &mut Request) -> IronResult<Response> {
// ...
// init some bindings like destination_html and destination_pdf
// ...
convert_to_pdf(destination_html, destination_pdf);
Ok( Response::with((status::Ok, "Done")) )
}
And the code of the called function:
fn convert_to_pdf(destination_html: &str, destination_pdf: &str) {
Command::new("xvfb-run")
.arg("-a")
.arg("wkhtmltopdf")
.arg(destination_html)
.arg(destination_pdf)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("failed to execute process");
}
The process works (the file is converted from HTML to PDF) and the response is returned to the browser. Everything is fine, but a zombie process is still there as a child of my app:
I don't know why and I don't know how to avoid it. What could I do?
The wkhtmltopdf
command is a long process, I don't want to call it synchronously and wait for its return. And I don't want to restart my Rust program (the parent of the zombie child) twice a day to kill zombies.