デーモンモードで実行する必要があるマルチスレッドWebサーバーを作成しています。コードを作成しましたが、デーモンモードで実行するとプログラムがクラッシュします。サーバーをデーモン化するためのコードを含めない場合、プログラムは正常に実行されています。誰かが私がどこで間違っているのか教えてもらえますか?
pid_t pid,cid;
pid = fork();
if(pid<0)
{
exit(EXIT_FAILURE);
}
if(pid>0)
{
exit(EXIT_SUCCESS);
}
umask(0);
cid=setsid();
std::cout<<"Process id after:"<<pid<<std::endl;
std::cout<<"Session id:"<<cid<<std::endl;
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
pthread_t t1,t2;
pthread_t threads[threadnum];
pthread_attr_t attr;
if ((s = socket(AF_INET, soctype, 0)) < 0) {
perror("socket");
exit(1);
}
pthread_attr_init(&attr);
pthread_create(&t1,NULL,setup_server,NULL); // thread for accepting the requests
pthread_create(&t2,NULL,scheduler,NULL); // thread for scheduling the requests