该模型是在单一迭代模型的基础上的改进,父进程只在一个死循环里进行accept,当一个客户端接入时,父进程会fork一个子进程,然后父进程关闭该连接的socket,并继续accept,等待下一个客户端接入,子进程可以关闭监听socket,然后去处理客户端请求,处理结束后关闭连接socket,结束自身进程,完整代码戳这里
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <semaphore.h>
#include <unistd.h>
#include <sys/types.h> /* See NOTES */
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <arpa/inet.h>
#include "public_head.h"
#include