NGINX----源码阅读---worker进程都干了啥

 1 static void
 2 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
 3 {
 4     ngx_int_t worker = (intptr_t) data;
 5 
 6     ngx_process = NGX_PROCESS_WORKER;
 7     ngx_worker = worker;
 8     //首先初始化worker
 9     ngx_worker_process_init(cycle, worker);
10     //修改worker进程的名字
11     ngx_setproctitle("worker process");
12 
13     for ( ;; ) {
14 
15         if (ngx_exiting) {
16             ngx_event_cancel_timers();
17 
18             if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
19             {
20                 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
21 
22                 ngx_worker_process_exit(cycle);
23             }
24         }
25 
26         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
27         //处理时间和定时器
28         ngx_process_events_and_timers(cycle);
29 
30         if (ngx_terminate) {
31             ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
32 
33             ngx_worker_process_exit(cycle);
34         }
35 
36         if (ngx_quit) {
37             ngx_quit = 0;
38             ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
39                           "gracefully shutting down");
40             ngx_setproctitle("worker process is shutting down");
41 
42             if (!ngx_exiting) {
43                 ngx_exiting = 1;
44                 ngx_close_listening_sockets(cycle);
45                 ngx_close_idle_connections(cycle);
46             }
47         }
48 
49         if (ngx_reopen) {
50             ngx_reopen = 0;
51             ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
52             ngx_reopen_files(cycle, -1);
53         }
54     }
55 }

worker的执行主要是初始化worker进程

修改worker进程名称

通过tag判断是否退出worker进程

最重要的是:进行时间和定时器的处理。

posted @ 2017-02-17 14:59  丶丨zuoluo  阅读(714)  评论(0编辑  收藏  举报