在linux上,最简单的解决方案可能是使用外部
ps命令:
>>> import os>>> data = [(int(p), c) for p, c in [x.rstrip('n').split(' ', 1) ... for x in os.popen('ps h -eo pid:1,command')]]在其他系统上,您可能必须将选项更改为
ps。
不过,您可能要
man在
pgrep和上运行
pkill。

在linux上,最简单的解决方案可能是使用外部
ps命令:
>>> import os>>> data = [(int(p), c) for p, c in [x.rstrip('n').split(' ', 1) ... for x in os.popen('ps h -eo pid:1,command')]]在其他系统上,您可能必须将选项更改为
ps。
不过,您可能要
man在
pgrep和上运行
pkill。