检测父进程何时退出 [英] Detect when parent process exits

查看:62
本文介绍了检测父进程何时退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将有一个用于处理网络服务器重启的父进程.它会发出信号让子进程停止监听新的请求,子进程会发出信号通知父进程它已经停止监听,然后父进程会发出信号通知新的子进程它可以开始监听了.通过这种方式,我们可以为该级别的重启实现不到 100 毫秒的停机时间(我也有零停机孙子重启,但这并不总是足够的重启).

I will have a parent process that is used to handle webserver restarts. It will signal the child to stop listening for new requests, the child will signal the parent that it has stopped listening, then the parent will signal the new child that it can start listening. In this way, we can accomplish less than 100ms down time for a restart of that level (I have a zero-downtime grandchild restart also, but that is not always enough of a restart).

服务管理器将在关闭时杀死父级.子节点如何检测父节点已结束?

The service manager will kill the parent when it is time for shutdown. How can the child detect that the parent has ended?

使用子进程的 stdin 和 stdout 发送信号.也许我可以检测到标准输入流的结尾?我希望避免轮询间隔.另外,如果可能的话,我希望这是一个非常快速的检测.

The signals are sent using stdin and stdout of the child process. Perhaps I can detect the end of an stdin stream? I am hoping to avoid a polling interval. Also, I would like this to be a really quick detection if possible.

推荐答案

你能不能把 退出侦听器在向子进程发出信号的父进程中?

Could you just put an exit listener in the parent process that signals the children?


您还可以使用 node-ffi(节点外部函数接口) 来调用...
prctl(PR_SET_PDEATHSIG, SIGHUP);
...在Linux中.( man 2 prctl )

这篇关于检测父进程何时退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆