Python获取系统所有进程PID及进程名称的方法示例

2018-09-22 00:49

阅读:694

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

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

  代码:

  运行结果:

  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,pnamebpsvc.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,pnametray.exe
pid-2320,pname-tomcat6w.exe
pid-2408,pnamesd.exe
pid-2596,pname-TaobaoProtect.exe
pid-2696,pname-aliwssv.exe
pid-2736,pname-conhost.exe
pid-2996,pnamebdoctor.exe
pid-3132,pnamerp.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,pnamese.exe
pid-6112,pnamese.exe
pid-4136,pname-wdswfsafe.exe
pid-2936,pnamese.exe
pid-5180,pnamese.exe
pid-4452,pnamese.exe
pid-5500,pnamese.exe
pid-1812,pnamese.exe
pid-2640,pname-eclipsePHP.exe
pid-4556,pname-javaw.exe
pid-2032,pnamese.exe
pid-6236,pname-QQ.exe
pid-5416,pnamese.exe
pid-4196,pnamese.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,pnamese.exe
pid-2404,pnamese.exe
pid-9432,pname-chrome.exe
pid-8692,pname-flashfxp.exe
pid-10116,pname-flashfxp.exe
pid-6628,pnamese.exe
pid-8504,pnamese.exe
pid-6464,pname-BFDesktopTips.exe
pid-11764,pname-audiodg.exe
pid-9364,pname-TTPlayer.exe
pid-6356,pnamese.exe
pid-8808,pnamese.exe
pid-8640,pname-eclipse.exe
pid-11344,pname-python2.exe
pid-5880,pname-conhost.exe
pid-4656,pname-chrome.exe
pid-3188,pnamese.exe
pid-9992,pnamese.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程序设计有所帮助。


评论


亲,登录后才可以留言!