本来搞个g_iChildProcessNum来记录当前进程数的,但是一直为0啊。。。
if(g_iChildProcessNum<g_iMaxChdNum)
{
iPid= fork();
switch (iPid)
{
case -1:
{
CloseSockfd(iClientSocketFD, LINE);
}
break;
case 0:
{
CloseSockfd(iServerSocketFD, LINE);
g_iChildProcessNum++;
HandleClient(iClientSocketFD);
g_iChildProcessNum--;
CloseSockfd(iClientSocketFD, LINE);
exit(0);
}
break;
default:
{
CloseSockfd(iClientSocketFD, LINE);
int sStatus;
pid_t childId = waitpid (-1, &sStatus, WNOHANG);
memset(logbuf,0,sizeof(logbuf));
sprintf(logbuf,"waitpid=[%d],status=[%d],line=[%d]\n",childId,sStatus,LINE);
lWriteLog(logfile,logbuf,strlen(logbuf),6);
}
break;
}
}
else
{
CloseSockfd(iClientSocketFD, LINE);
memset(logbuf,0,sizeof(logbuf));
sprintf(logbuf,"Too many client connection,g_iChildProcessNum=[%d],g_iMaxChdNum=[%d],line=[%d]\n",g_iChildProcessNum,g_iMaxChdNum,LINE);
lWriteLog(logfile,logbuf,strlen(logbuf),6);
}