This is a reasonable thing to wonder about. Here is a high-level summary of what generally happens: a CGI program will be spawned off by the HTTP server as a separate process which is expected to send its results (valid web content, HTML etc, if all went well) to stdout. The HTTP server collects that, does a bit of post-processing on it and then slings it all back to the source of the original HTTP request.
Re^3: What filehandle should be used for HTML prints via CGI??
Replies are listed 'Best First'.