use parity_daemonize::{AsHandle, daemonize};
use std::{thread, time, process, io};
use self::io::Write;
fn main() {
match daemonize("pid_file") {
Ok(mut handle) => {
let mut count = 0;
loop {
println!("Count: {}", count);
if count == 5 {
handle.detach_with_msg("count has reached 5, continuing in background");
}
thread::sleep(time::Duration::from_secs(1));
count += 1;
}
}
Err(e) => {
eprintln!("{}", e);
let _ = io::stderr().flush();
process::exit(1);
}
}
}