1 #!/usr/bin/python2 3 import psutil4 5 pids = psutil.pids()6 for pid in pids:7 p = psutil.Process(pid)8 print("pid-%d,pname-%s" %(pid,p.name()))9 10 运行结果如下:GreydeMac-mini:01_系统基础信息模块详解 greyzhang$ python pid.py