Nginx進程信號
舉個例子說明
Nginx是父子進程的通信是通過信號進行管理的,使用ps -ef可以看到當前進程的ID和其父進程的ID。
[root@www ~]# ps -ef | grep nginx
root 1961 1 0 11:14 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 1965 1961 0 11:14 ? 00:00:00 nginx: worker process
使用-s reload會把之前的worker進程優雅的退出然後再使用新的配置項去啓動新的worker進程,我這裏沒有改變配置,但是可以看到,老的一個worker子進程將會退出還會生成新的worker子進程。
[root@www ~]# /usr/local/nginx/sbin/nginx -s reload
[root@www ~]# ps -ef | grep nginx
root 1961 1 0 11:14 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 1971 1961 0 11:15 ? 00:00:00 nginx: worker process
可以看到之前的子進程1965現在已經不在了,反而1961啓動1971子進程。reload信號和HUP信號是相同的,現在向nginx的master進程發送HUP信號,是不是會發生相同的結果呢?
nginx -s reload用兩幅圖總結如下:
總結一下
[root@www ~]# ps -ef | grep nginx
root 1961 1 0 11:14 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 1976 1961 0 11:17 ? 00:00:00 nginx: worker process
向對應的stop,quit也有信號,在worker進程退出的時候會向master進程發送信號,當父進程收到信號之後知道子進程退出了,會新啓worker進程來維持配置文件裏面配置的worker進程的進程數
[root@www ~]# kill -SIGTERM 1976
[root@www ~]# ps -ef | grep nginx
root 1961 1 0 11:14 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 1980 1961 0 11:22 ? 00:00:00 nginx: worker process
可以看到1976進程已經退出了,但是nginx又重新啓動了新的進程1980。所以在命令行的命令是父進程對子進程發送信號而已。