CGI scripts are run by the operating system.
Usually web servers assume that the file is a CGI script if it is located in a specific directory (often called cgi-bin ) and has an executable bit.
If the web server considers the file to be a CGI script, it fork s, sets some environment variables and other little things, and then asks the operating system to execute it.
The operating system sees if it can execute it directly, and if so, it will happen. Otherwise, it searches for hashbang and uses this to execute the script.
source share