Run Tiny server
I have previously written the source code parsing of the Tiny server in the book Understanding computer systems, but the book does not introduce how to run Tiny. Next I will introduce how to run Tiny.
The source files of Tiny include tiny. c, csapp. c, and csapp. h. In addition, create a new cgi-bin directory in the root directory to store CGI programs.
In-depth understanding of computer systems (original book version 2nd) PDF clear Chinese Version
Method 1:
1. Put all source files tiny. c, csapp. c, and csapp. h in the same directory. Additionally, the photo.jpg file is stored in the same directory as the test file. Run the following command:
$gcc -o tiny tiny.c csapp.c -lpthread
Note:-lpthread is added because some functions in csapp. c use multi-threaded libraries.
2. Place the CGI program for testing in the cgi-bin directory and compile it into an executable program.
$gcc -o adder adder.c
3. Run the Tiny program and specify the port number (1024-49151 is available, others are well-known ports)
$./tiny 1024
4. Now Tiny is running. Open your browser and you will be able to access it.
Access static content
Access dynamic content
Method 2: use Makefile to compile Tiny:
I have read some knowledge about Makefile some time ago, so I will try to run Tiny with the make command.
1. Unlike method 1, create the include directory under the working directory and place csapp. h under the directory. Then write the Makefile as follows:
CFLAGS= -Wall -g -I./include LIBS=-lpthreadtiny: tiny.o csapp.o cc -o tiny tiny.o csapp.o $(LIBS)clean: rm *.o tiny
Use CFLAGS in Makefile to set compilation parameters and specify the header file location as./include. Use LIBS to specify the library to be linked.
2. Enter the make command in the working directory to complete the Tiny compilation link.
3. The subsequent operations are the same as those described in method 1.
This article permanently updates the link address: