II use daemon(1,0) to demonize the process. But Daemon() API is deprecated long back.
So tried achieving demonize through fork(), but service is getting closed when I close the parent process. What should be the issue?
Code snippet is added below.
Please suggest any thing is wrong in below code.
bool daemon_service::daemon_service_impl::daemonise()
{
int ret = fork();
if (ret == -1)
{
// fork() failed.
last_error_ = last_system_error();
return false;
}
if (ret != 0)
{
// This is the parent non-daemon.
exit(EXIT_SUCCESS);
}
// This must be the child daemon.
is_daemon_ = true;
last_error_.erase();
// detach from the terminal
setsid();
// Close fd's 0,1,2. Needed if started by rsh
//close_low_fds();
close(0); close(1); close(2);
return true;
}