回收子进程是书本537页的内容
在tiny.c文件加以下代码,记得重新编译哦
书中提到CGI是在动态内容中的,所以题目的意思应该是在动态内容里面回收
void handler1(int sig)
{
int olderrno = errno;
while (waitpid(-1,NULL,0)>0){
Sio_puts("Handler reaped child\n");
}
if(errno != ECHILD)
Sio_error("waitpid error");
Sleep(1);
errno = olderrno;
}
/*
void serve_dynamic(int fd, char *filename, char *cgiargs)
{
char buf[MAXLINE], *emptylist[] = { NULL };
/* Return first part of HTTP response */
sprintf(buf, "HTTP/1.0 200 OK\r\n");
Rio_writen(fd, buf, strlen(buf));
sprintf(buf, "Server: Tiny Web Server\r\n");
Rio_writen(fd, buf, strlen(buf));
if(signal(SIGCHLD,handler1) == SIG_ERR)
unix_error("signal error");
if (Fork() == 0) { /* Child */ //line:netp:servedynamic:fork
/* Real server would set all CGI vars here */
setenv("QUERY_STRING", cgiargs, 1); //line:netp:servedynamic:setenv
Dup2(fd, STDOUT_FILENO); /* Redirect stdout to client */ //line:netp:servedynamic:dup2
Execve(filename, emptylist, environ); /* Run CGI program */ //line:netp:servedynamic:execve
}
/*Wait(NULL); Parent waits for and reaps child */ //line:netp:servedynamic:wait
}