使用 python 在 mac 上查询服务状态

Querying the Status of a Service on mac using python

就像 windows 中的 Windows32ServiceUtil api 我们如何通过 mac os 中的名称检查服务是否 运行 x.

我终于通过 psutil 库找到了解决方案

import psutil
all_processes = [p.as_dict() for p in psutil.process_iter()]

给出os

中所有进程信息的字典

现在我们可以遍历字典中的路径、exepath、进程名称。 和 return pid 根据需要。 for i in all_processes: if 'Google Chrome' in i['name'] return i['pid']

如果是python进程我们可以通过exe的路径查看