圆月山庄资源网 Design By www.vgjia.com

本文实例讲述了Python获取系统所有进程PID及进程名称的方法。分享给大家供大家参考,具体如下:

psutil模块中提供了进程管理方法,引用其中的几个方法就能够获得进程的相关信息。简单写个小脚本测试一下,顺便看看本机Windows7系统中到底运行着多少个进程,进程都是什么。

代码:

# -*- coding: utf-8 -*-
#! python2
#!/usr/bin/python
import psutil
pids = psutil.pids()
for pid in pids:
  p = psutil.Process(pid)
  print("pid-%d,pname-%s" %(pid,p.name()))

运行结果:

pid-0,pname-System Idle Process
pid-4,pname-System
pid-288,pname-smss.exe
pid-428,pname-csrss.exe
pid-480,pname-wininit.exe
pid-500,pname-csrss.exe
pid-544,pname-services.exe
pid-576,pname-winlogon.exe
pid-588,pname-lsass.exe
pid-596,pname-lsm.exe
pid-716,pname-svchost.exe
pid-800,pname-svchost.exe
pid-864,pname-svchost.exe
pid-932,pname-svchost.exe
pid-1012,pname-svchost.exe
pid-1128,pname-svchost.exe
pid-1324,pname-ZhuDongFangYu.exe
pid-1348,pname-svchost.exe
pid-1468,pname-spoolsv.exe
pid-1608,pname-svchost.exe
pid-1692,pname-360bpsvc.exe
pid-1736,pname-AlibabaProtect.exe
pid-1892,pname-QQProtect.exe
pid-1928,pname-secbizsrv.exe
pid-1996,pname-TBSecSvc.exe
pid-2004,pname-taskhost.exe
pid-356,pname-httpd.exe
pid-348,pname-mysqld.exe
pid-592,pname-dwm.exe
pid-1560,pname-explorer.exe
pid-1304,pname-wwbizsrv.exe
pid-2248,pname-360tray.exe
pid-2320,pname-tomcat6w.exe
pid-2408,pname-360sd.exe
pid-2596,pname-TaobaoProtect.exe
pid-2696,pname-aliwssv.exe
pid-2736,pname-conhost.exe
pid-2996,pname-360bdoctor.exe
pid-3132,pname-360rp.exe
pid-3740,pname-httpd.exe
pid-3072,pname-QQ.exe
pid-3180,pname-svchost.exe
pid-3544,pname-baidupinyin.exe
pid-3788,pname-TXPlatform.exe
pid-4124,pname-svchost.exe
pid-5104,pname-SoftMgrLite.exe
pid-6000,pname-360se.exe
pid-6112,pname-360se.exe
pid-4136,pname-wdswfsafe.exe
pid-2936,pname-360se.exe
pid-5180,pname-360se.exe
pid-4452,pname-360se.exe
pid-5500,pname-360se.exe
pid-1812,pname-360se.exe
pid-2640,pname-eclipsePHP.exe
pid-4556,pname-javaw.exe
pid-2032,pname-360se.exe
pid-6236,pname-QQ.exe
pid-5416,pname-360se.exe
pid-4196,pname-360se.exe
pid-5380,pname-chrome.exe
pid-5220,pname-chrome.exe
pid-4652,pname-chrome.exe
pid-7880,pname-chrome.exe
pid-9168,pname-chrome.exe
pid-6432,pname-chrome.exe
pid-6680,pname-360se.exe
pid-2404,pname-360se.exe
pid-9432,pname-chrome.exe
pid-8692,pname-flashfxp.exe
pid-10116,pname-flashfxp.exe
pid-6628,pname-360se.exe
pid-8504,pname-360se.exe
pid-6464,pname-BFDesktopTips.exe
pid-11764,pname-audiodg.exe
pid-9364,pname-TTPlayer.exe
pid-6356,pname-360se.exe
pid-8808,pname-360se.exe
pid-8640,pname-eclipse.exe
pid-11344,pname-python2.exe
pid-5880,pname-conhost.exe
pid-4656,pname-chrome.exe
pid-3188,pname-360se.exe
pid-9992,pname-360se.exe
pid-12116,pname-cmd.exe
pid-9248,pname-conhost.exe
pid-7208,pname-python2.exe
pid-1832,pname-conhost.exe

注:这里使用了psutil模块,若提示Unresolved import: psutil,则需要使用如下命令进行安装:

pip install psutil

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python进程与线程操作技巧总结》、《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

标签:
Python,获取,系统,进程PID,进程名称

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。