The code below prints "Bye!" as expected, but leaves a process running in the background:
use nix::unistd::daemon; // nix 0.17.0
use tokio::runtime::Builder; // tokio 0.2.11 features rt-threaded
fn main() {
Builder::new()
//.basic_scheduler() // clean exit
.threaded_scheduler() // process keeps running
.build()
.unwrap()
.block_on(async {
daemon(true, true).unwrap();
println!("Bye!");
})
}
On my computer (Arch Linux, Rust 1.41), the program will correctly print "Bye!" and cleanly exit if the threaded scheduler is replaced with the basic scheduler, or if the process is not daemonized.
What could possibly be the reasons that the threaded scheduler does not play nicely with daemon()
?