SYNOPSIS

   #include <afblib/preforked_service.h>
   typedef void (*session_handler)(int fd, int argc, char** argv);
   void run_preforked_service(hostport* hp, session_handler handler,
         unsigned int number_of_processes, int argc, char** argv) {


DESCRIPTION

run_preforked service creates a socket with the given address specified by hp (see hostport) and creates the given number of processes to which the socket is inherited. Each of these processes creates another child process that is ready to accept an incoming connection. Whenever a new connection is dispatched to one of the waiting processes, a new child process is created. This means that there will be always number_of_processes processes ready to accept a connection.

If one of the child processes terminates, it will be restarted. If the main process gets a SIGTERM signal, this will be distributed to all children, causing all processes to terminate. Running sessions, however, will not be interrupted.

run_preforked_service terminates only in case of errors or in case of SIGTERM (errno is EINTR in this case). The forked-off processes do not become zombies as the parent process waits for them to terminate.


AUTHOR

Andreas F. Borchert