In order to get the correct pid, we should daemonize before writing the pidfile