void DaemonInit(void)
{
pid_t pid;
pid_t sid;
// fork to leave parent
pid = fork ();
if (pid < 0)
{
std::cout << "failed to fork!" << std::endl;
exit (EXIT_FAILURE);
}
else if (pid > 0)
{
//parent process go to exit
exit (EXIT_SUCCESS);
}
//child process
sid = setsid ();
if (sid < 0)
{
std::cout << "Failed to set session id." << std::endl;
exit (EXIT_FAILURE);
}
return;
}