¼ÒÄϼ­¹ö¸¦ ¸¸µé°í ÀÖ½À´Ï´Ù. ¼­¹ö´Â Ŭ¶óÀ̾ðÆ® ¿äû½Ã¿¡ ÀÚ½ÄÀ» fork ½ÃÅ°°í ÀÚ½ÄÇÁ·Î¼¼½º´Â DB¸¦ Àо °á°ú¸¦ Ŭ¶óÀ̾ðÆ®¿¡ µ¹·ÁÁÖ°í exitÇÕ´Ï´Ù. ¹®Á¦´Â ÀÚ½ÄÇÁ·Î¼¼½º°¡ Á¾·áµÉ ¶§ ºÎ¸ðÇÁ·Î¼¼½ºÀÇ ¼ÒÄÏ select ÇÔ¼ö¿¡ (-1)¿¡·¯¸¦ ¹ß»ý½Ãŵ´Ï´Ù. ÀÌ°Ô ¾î¶² ½Ã±×³ÎÀÎÁö, ¾î¶»°Ô ÇØ°áÇØ¾ß ÇÒÁö Àß ¸ð¸£°Ù½À´Ï´Ù. °í¼ö´Ôµé µµ¿ÍÁÖ¼¼¿ä ^^ void z_handler(int sig) { pid_t pid; int rtn; pid=waitpid(-1, &rtn, WNOHANG); } int main(int argc, char **argv) { ... /* ½Ã±×³Î Çڵ鷯 µî·Ï */ /* SIGCHLD */ chldact.sa_handler=z_handler; sigemptyset(&chldact.sa_mask); chldact.sa_flags=0; c_state=sigaction(SIGCHLD, &chldact, 0); if(c_state != 0){ exit(1); } if((sockfd=socket(PF_INET,SOCK_STREAM,0)) < 0) { exit(1); } memset(&serv_addr,0x00,sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(portNum); serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); if((bind(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr))) < 0){ close(sockfd); shutdown(sockfd, 0); exit(1); } if(listen(sockfd,5) == -1){ close(sockfd); shutdown(sockfd, 0); exit(1); } FD_ZERO(&reads); FD_ZERO(&temps); FD_SET(sockfd, &reads); fd_max=sockfd; while (1){ int fd; int buf_len ; int srtn; char rcvBuf[BUFSIZE]; temps=reads; timeout.tv_sec = 3; timeout.tv_usec = 0; srtn = select(fd_max+1, &temps, 0, 0, &timeout); if(srtn < 0){ sleep(3); continue; } for(fd=0; fd 0){ if ((chldpid = fork()) < 0 ){ write_log("fork error\n"); close(fd); continue; } if(chldpid == 0) { close(sockfd); childJob(fd, rcvBuf); FD_CLR(fd, &reads); close(fd); exit(0); } else{ /* ºÎ¸ð */ close(fd); FD_CLR(fd, &reads); } } } } } /* for */ } /* while */ }