且构网

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

使用 Python 在 Windows 上检查进程是否正在运行

更新时间:2023-12-05 12:07:22

您不能依赖 Linux 或 Windows 中的锁定文件.我会咬紧牙关,遍历所有正在运行的程序.我真的不相信它会像你想象的那样昂贵".psutil 是一个优秀的跨平台 python 模块电缆,用于枚举系统上所有正在运行的程序.

You can not rely on lock files in Linux or Windows. I would just bite the bullet and iterate through all the running programs. I really do not believe it will be as "expensive" as you think. psutil is an excellent cross-platform python module cable of enumerating all the running programs on a system.

import psutil    
"someProgram" in (p.name() for p in psutil.process_iter())