Andrew Savige (
Wed, 23 Oct 1996 13:47:37 +1000

Message-Id: <>
Date: Wed, 23 Oct 1996 13:47:37 +1000
From: Andrew Savige <>
Subject: forking

As will soon become obvious, I am new to fast-cgi.

I am manually starting a remote 'responder' process on
host 'knob', say, with something like:
   cgi-fcgi -start -connect :9992 /fred/responder
and I'm connecting to it from within a cgi script on
host 'fred', say, with:
   cgi-fcgi -bind -connect knob:9992

With the responder consisting of a simple FCGI_Accept()
loop, I got everything working fine.

Then I got a little more ambitious and fell down a hole.

What I am trying to do is to have responder immediately
fork a new process to handle the (possibly lengthy) request,
then wait for the next request and so on.  Is fast-cgi
designed to work this way?  If not, what is the recommended
way of writing a remote responder?

To give you a more precise idea of what I am doing, here
is a rough map of the responder code;

   while (FCGI_Accept() >= 0) {
      if ((pid = fork()) < 0) {
      } else if (pid == 0) {
         /* child */
         printf("Content-type: text/plain\r\n\r\n");
         printf("this is a test\n");
         sleep(2);  /* simulate a lengthy request */
      /* parent continues */

The child's response works, but the parent then exits
the FCGI_Accept() loop (maybe FCGI_Accept() also calls
FCGX_Finish() and that causes a problem?).

Please help.

-- Andrew
Andrew Savige