lighttpd1.4.20 Source Analysis-Working model

Source: Internet
Author: User

LIGHTTPD's working model is simple-a multiple-process model of a main process plus multiple working processes, known as the Watcher-worker model.

The entry (main function) of the entire program is in the Server.c file. At the beginning of the main function must be processing parameters and a variety of complex initialization work. There are two places to focus on together. The first one is the following statement:

1 if (test_config) //没有进行任何测试。。。
2 {
3     printf("Syntax OK\n");
4 }

This if statement is to determine whether the syntax of the configuration file is legitimate. But, obviously, no tests were carried out, but only a word was printed.

The second one is the function daemonize (). The role of this function is to get the program into daemon. The details of the function are as follows:

1 static void daemonize(void)
2 {
3         /*
4          * 忽略和终端读写有关的信号
5          */
6 #ifdef SIGTTOU
7         signal(SIGTTOU, SIG_IGN);
8 #endif
9 #ifdef SIGTTIN
10         signal(SIGTTIN, SIG_IGN);
11 #endif
12 #ifdef SIGTSTP
13         signal(SIGTSTP, SIG_IGN);
14 #endif
15         if (0 != fork()) /* 产生子进程,父进程退出 */
16             exit(0);
17         if (-1 == setsid())/* 设置子进程的设置ID */
18             exit(0);
19         signal(SIGHUP, SIG_IGN);/* 忽略SIGHUP信号 */
20         if (0 != fork())/* 再次产生子进程,父进程退出 */
21             exit(0);
22         if (0 != chdir("/"))/* 更改工作目录为根目录 */
23             exit(0);
24 }

Here the authors use the standard method of producing *nix daemon. Two times call fork and exit the parent process. For specific reasons, readers can refer to the Daemon section of the UNIX Environment Advanced Programming (APUE).

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.