// ngx_process这个变量记录了接收到信号的进程类型,这里很明显是master process(因为通过master的pid发出的信号)
switch (ngx_process) {
case NGX_PROCESS_MASTER:
case NGX_PROCESS_SINGLE:
switch (signo) {
…
case ngx_signal_value(NGX_CHANGEBIN_SIGNAL):
/* 这里给出了详细的注释,更通俗一点来讲,就是说,进程现在是一个
* master(新的master进程),但是当他的父进程old master还在运行的话,
* 这时收到了USR2信号,我们就忽略它,不然就成了新master里又要生成
* master。。。另外一种情况就是,old master已经开始了生成新master的过程
* 中,这时如果又有USR2信号到来,那么也要忽略掉。。。(不知道够不够通俗=.=)
*/
if (getppid() > 1 || ngx_new_binary > 0) {
/*
* Ignore the signal in the new binary if its parent is
* not the init process, i.e. the old binary's process
* is still running. Or ignore the signal in the old binary's
* process if the new binary's process is already running.
*/
action = ", ignoring";
ignore = 1;
break;
}
// 最重要的操作在这里,通过将ngx_change_binary置为1,来告诉master
// 应该去启动一个新的实例了,也就是说,master里面在检测到这个变量为// 1时,就会做新nginx实例的生成工作了
ngx_change_binary = 1;
action = ", changing binary";
break;…
}
}