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.


In reply to Re: Apache invoke perl by fizbin
in thread Apache invoke perl by mkirank

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.