Run the Tiny server and the Tiny server

Source: Internet
Author: User

Run the Tiny server and the Tiny server
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.

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. 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. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.