子进程在 Python 中检测父进程的死亡 [英] Child process detecting the parent process' death in Python

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

问题描述

有没有办法让 Python 中的子进程检测父进程是否已经死亡?

Is there a way for a child process in Python to detect if the parent process has died?

推荐答案

如果你的 Python 进程在 Linux 下运行,并且暴露了 prctl() 系统调用,你可以使用答案 此处.

If your Python process is running under Linux, and the prctl() system call is exposed, you can use the answer here.

这会导致在父进程终止时向子进程发送信号.

This can cause a signal to be sent to the child when the parent process dies.

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

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