Nginx Source Analysis-worker Process creation

Source: Internet
Author: User

Nginx Source Analysis-worker Process creation

Assuming the ngx_init_cycle is over now (after all, this function is really huge), that is, the initialization of Nginx has ended. So look at how to create the process model ngx_master_process_cycle.

In this function, the first thing is a signal, then register the signal that needs attention (this time the processing function of the signal has been registered), it can be seen that the master process has 10 signals to follow. such as SIGCHLD and so on. Next Call the Ngx_start_worker_processes function, this function is to open the worker process function, the rest of the master process into a dead loop, this cycle is waiting for the external signal activation, if there is a signal, then update the time , the master process blocks most of the time on the Sigsuspend function. Different signals are processed differently, and some signals need to be passed to the worker process.

Look at the ngx_start_worker_processes function, which has a for loop that creates a worker process in a loop that opens the Socketpair between the parent and child processes, Ngx_pass_open_ The channel function passes its own information to all other processes.

The Ngx_spawn_process function creates the Socketpair, then fork, and the child process calls Ngx_worker_process_cycle.

Ngx_worker_process_cycle This function is also very important, in the Ngx_worker_process_init function to mask all the signal processing functions inherited from the parent process, while closing the socketpair socket inherited from the parent process, This pair of Socketpair, where 0 in order to write, 1 to read, so at the same time need to close their own write, just to open their own reading can, at the same time on the read socket register Ngx_channle_handler function, this function is to modify the global variables, exists for the worker process to accept signals passed by the parent process. The ngx_add_channel_event adds its own 1 to the listening queue. The worker process then enters the dead loop, either handling the event or processing the signal.

Ngx_process_events_and_timers This function is to deal with business.

Next, the whole process of interpreting the business!

Nginx Source Analysis-worker Process creation

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.