Figure 7. Use of the SIGCHLD signal.

     int reaper(); 
     ... 
     signal(SIGCHLD, reaper); 
     listen(f, 5); 
     for (;;) { 
          int g, len = sizeof (from);

          g = accept(f, (struct sockaddr *)&from, &len,); 
          if (g < 0) { 
               if (errno != EINTR) 
                    syslog(LOG_ERR, "rlogind: accept: %m"); 
               continue; 
          } 
          ... 
     } 
     ... 
     #include <wait.h> 
     reaper() 
     { 
          union wait status;

          while (wait3(&status, WNOHANG, 0) > 0) 
               ; 
     }