This preview shows page 1. Sign up to view the full content.
Unformatted text preview: . ¯ ¯ Since servers typically run for long periods of time, we must include a SIGCHLD handler that reaps zombie children (lines 8–14). Since SIGCHLD signals are blocked while the SIGCHLD handler is executing, and since Unix signals are not queued, the SIGCHLD handler must be prepared to reap multiple zombie children. Notice that the parent and the child close their respective copies of connfd (lines 39 and 36 respectively). This especially important for the parent, which must close its copy of the connected descriptor to avoid a memory leak that will eventually crash the system. 640
data transfers client 1 clientfd data transfers CHAPTER 12. NETWORK PROGRAMMING
child 1 connfd(4) listenfd(3) server client 2 clientfd child 2 connfd(5) Figure 12.33: Server forks another child to service the new client. ¯ Because of the reference count in the socket’s ﬁle table entry (Figure 12.21), the socket will not be closed until both the parent’s and child’s copies of connfd are closed. Discussion
Of the concurrent-server designs that we will study in this section, process-based designs are by...
View Full Document