psutil python库

github源码
https://github.com/giampaolo/psutil

由pid获取进程名字容易,反之呢?
我想用psutil来做进程管理,那么我怎么通过进程名字获得进程pid呢?

import psutil
psutil.pids()

在远古时期可能有一种方法,但是近代已经不行了
Issue: Deprecate psutil.get_process_list() #273
psutil.get_process_list()
最新的方法可能是:
list(psutil.process_iter())
Reasons: 
- it is just a one liner (return list(process_iter()))
- process_iter() should be preferred in general
- it's not even documented
posted @ 2022-03-06 10:39  叶常落  阅读(19)  评论(0编辑  收藏  举报