简体   繁体   English

如何在Linux中监视子进程状态

[英]How to monitor a child process state in Linux

I have a control service that its functionality is to manage another process in the system. 我有一个控制服务,它的功能是管理系统中的另一个进程。 I have to run this process, re-run it if it's unexpectedly closed, and close it manually upon user request. 我必须运行此过程,如果意外关闭了它,请重新运行它,并应用户要求手动关闭它。

Can you please advise me how to do that in Linux? 您能告诉我如何在Linux中执行此操作吗? should I save the child process PID and check its state periodically? 我应该保存子进程PID并定期检查其状态吗? can I register to some system events that will notify me if the application running state has been changed? 如何注册一些系统事件,如果应用程序的运行状态已更改,这些事件将通知我?

Thanks in advance. 提前致谢。

should I save the child process PID and check its state periodically? 我应该保存子进程PID并定期检查其状态吗?

No, if the child exits, the parent will receive signal SIGCHLD , so you can install signal handler to react on this event. 不,如果子级退出,则父级将收到信号SIGCHLD ,因此您可以安装信号处理程序以对此事件做出反应。

See sigaction(2) for how to install a signal handler, see signal(7) for general information about signal. 有关如何安装信号处理程序的信息,请参见sigaction(2) ;有关信号的一般信息,请参见signal(7)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM