In how much detail do you want this answer?
The essential spawning of the child process is done in the file mod_cgi.c, viewable at http://cvs.apache.org/viewcvs.cgi/apache-1.3/src/modules/standard/mod_cgi.c?view=markup
The function you're looking for is cgi_handler. You might also be interested in the function ap_bspawn_child which is, I'm certain, somewhere in the ap/ source subdirectory.
From the source, it appears that what happens is that the child CGI process is opened with pipes connected to its standard input and standard output - the apache process then feeds stuff to the child process over these pipes and acts as a middleman between the process and the network (for example, unless you have a "nph" CGI script, the apache process will add in certain header fields to the response). Standard error of the CGI process appears to remain connected to the error log file (directly, without going through a pipe).
For more on communicating with child processes through pipes, consult any good book on unix programming if you want to do this in C (especially look for something that describes the proper use of the dup2 function). If you want to do this kind of stuff in perl, look at the peripc manpage. |