runAsDaemon function to work in the background