Nginx进程信号


Nginx 进程管理 信号

 

举个例子说明


Nginx是父子进程的通信是通过信号进行管理的,使用ps -ef可以看到当前进程的ID和其父进程的ID。

[[email protected] ~]# 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子进程。

 

[[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload

[[email protected] ~]# 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用两幅图总结如下: 

 

Nginx 进程管理 信号

Nginx 进程管理 信号

 

 

总结一下


  [[email protected] ~]# 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进程的进程数

 

[[email protected] ~]# kill -SIGTERM  1976

[[email protected] ~]# 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。所以在命令行的命令是父进程对子进程发送信号而已。

相关文章:

  • 2021-11-28
  • 2021-12-26
  • 2021-07-31
  • 2021-09-22
  • 2021-12-30
  • 2022-12-23
  • 2021-11-15
  • 2021-06-15
猜你喜欢
  • 2021-09-18
  • 2022-02-10
  • 2021-04-08
  • 2022-12-23
  • 2021-12-06
  • 2021-09-26
  • 2021-07-22
相关资源
相似解决方案