Question: If we were to delete line 33 of Figure12.5, which closes the connected descriptor, the code would still be correct, in the sense that there
If we were to delete line 33 of Figure12.5, which closes the connected descriptor, the code would still be correct, in the sense that there would be no memory leak. Why?
Figure12.5

1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include "csapp.h" void echo(int connfd); void sigchld_handler (int sig) { } while (waitpid (-1, 0, WNOHANG) > 0) ; return; int main(int argc, char **argv) { } int listenfd, connfd; socklen_t clientlen; struct sockaddr_storage clientaddr; if (argc ! 2) { fprintf(stderr, "usage: %s ", argv[0]); exit(0); } Signal (SIGCHLD, sigchld_handler); listenfd = Open_listenfd (argv[1]); while (1) { clientlen sizeof (struct sockaddr_storage); }| connfd = Accept (listenfd, (SA) &clientaddr, &clientlen); == 0) { if (Fork () Close (listenfd); /* Child closes its listening socket */ echo (connfd); /* Child services client */ Close (connfd); /* Child closes connection with client */ /* Child exits */ exit(0); == } Close (connfd); /* Parent closes connected socket (important!) */
Step by Step Solution
3.35 Rating (161 Votes )
There are 3 Steps involved in it
When a process terminates for any rea... View full answer
Get step-by-step solutions from verified subject matter experts
