且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Linux 上使用 Python 检查进程是否仍在运行?

更新时间:2023-12-05 09:48:40

Mark 的回答是要走的路,毕竟这就是/proc 文件系统存在的原因.对于一些更多的复制/粘贴:

Mark's answer is the way to go, after all, that's why the /proc file system is there. For something a little more copy/pasteable:

 >>> import os.path
 >>> os.path.exists("/proc/0")
 False
 >>> os.path.exists("/proc/12")
 True