#if 0 //fork a new process will cause thread run ( socket select() error or blocked!)
int pid=fork();
if (pid<0)
exit(1);
else if (pid>0)
exit(0);
else //if (pid=0) //child
{
while(1)
{
sleep(1);
}
}
#else
while(1)
{
sleep(1);
}
int pid=fork();
if (pid<0)
exit(1);
else if (pid>0)
exit(0);
else //if (pid=0) //child
{
while(1)
{
sleep(1);
}
}
#else
while(1)
{
sleep(1);
}
#endif
创建调用select()的线程的进程必须保留。
本文探讨了在创建进程并调用select()函数时遇到socket选择错误或阻塞的问题,通过代码实例展示了如何解决该问题。
913

被折叠的 条评论
为什么被折叠?



