NAME

run_preforked_service -- run a TCP-based service on a given hostport

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 waits until a new connection is dispatched to it. Then it will run the session and another preforked process will be created as replacement. This means that there will be always number_of_processes processes ready to accept a connection.

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 and their exit status will not be available through wait.

AUTHOR

Andreas F. Borchert