如何在 Linux 上使用 Python 获取正在运行的进程列表?
最佳答案
IMO 查看 /proc
文件系统比破解 ps
的文本输出要好。
import os
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
for pid in pids:
try:
print open(os.path.join('/proc', pid, 'cmdline'), 'rb').read().split('\0')
except IOError: # proc has already terminated
continue
关于python - 通过 Python 在 Linux 上的进程列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2703640/