The "CGI Process" you talk about is the CGI program. The CGI program can be a script in any language or a compiled executable.
The details of how the operating system actually executes the CGI program code (your steps 2, 3, 4, and 5) are not really necessary to understand how CGI works.
This is how I think of it (Your steps 2-5 are compressed into step 2 here):
- Apache receives a request - sees it's a request for a CGI program
- Apache executes the CGI program, passing the parameters from the request to the CGI program in the environment (as environment variables).
- The CGI program gets the parameters from the environment, performs any required processing, and writes the web page on standard output.
- Apache receives the web page from the CGI program's standard output and transmits it to the web client (usually your web browser).
Most of the details you discussed in your steps 2-5 are covered in the execve
man page (on Linux contains working code examples): man 2 execve
. You may also want to look at fork
. This is getting off the topic of CGI and into the topic of the Unix process model. Better for another question later.
For an accurate and detailed description of CGI see the internet draft of the specification:
The WWW Common Gateway Interface Version 1.1
See Also
Apache Tutorial: Dynamic Content with CGI
#!
line and execs the specified interpreter (or the default,/bin/sh
if there is no shebang).