Run C Program On Web Server

C++ Simple Web Server
Chmod 755 simplest.plThis tells UNIX that the script is executable.You have just seen the basic idea behind CGI scripting. It is really that simple! A program executes and its output is sent to the browser that called the script. Normal output sent to stdout is what gets sent to the browser.The whole point of CGI scripting, however, is to create dynamic content - each time the script executes, the output should be different. After all, if the output is the same every time you run the script, then you might as well use a static page. The following C program demonstrates very simple dynamic content.
Run C Program On Web Server Ip
Gcc count.c -o count.cgiCreate another text file named count.txt and place a single zero in it. By placing counter.cgi and count.txt in the cgi-bin directory, you can run the script. All that the script does is generate a page that says, 'The current count is: X,' where X increments once each time you run the script. Try running it several times and watch the content of the page change!The count.txt file holds the current count, and the little incrementcount function is the function that increments the count in the count.txt file. This function opens the count.txt file, reads the number from it, increments the number and writes it back to the file. The function actually tries to open the file twice.
How To Compile Cgi File
It does that just in case two people try to access the file simultaneously. It certainly is not a foolproof technique, but for something this simple it works. If the file cannot be opened on the second attempt, -1 is the error value returned to the caller. A more sophisticated program would recognize the -1 return value and generate an appropriate error message.