且构网

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

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

更新时间:2023-12-05 09:31:10

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