1use parity_daemonize::{AsHandle, daemonize};
2use std::{thread, time, process, io};
3use self::io::Write;
4
5fn main() {
6 match daemonize("pid_file") {
7 Ok(mut handle) => {
9 let mut count = 0;
10 loop {
11 println!("Count: {}", count);
13 if count == 5 {
14 handle.detach_with_msg("count has reached 5, continuing in background");
15 }
16 thread::sleep(time::Duration::from_secs(1));
17 count += 1;
18 }
19 }
20 Err(e) => {
23 eprintln!("{}", e);
25 let _ = io::stderr().flush();
27 process::exit(1);
28 }
29 }
30}