python调用win7命令清理系统无用进程方法,pythonwin7,求大侠指点一下我的代码,
python调用win7命令清理系统无用进程方法,pythonwin7,求大侠指点一下我的代码,
求大侠指点一下我的代码,我要做的是python调用win7命令清理系统无用进程方法。
我的思路是:
用系统命令 tasklist 列出当前running进程;
检索出无用进程的PID;
用系统命令 taskkill 杀掉进程。
python调用win7命令清理系统无用进程方法代码如下:
# -*- coding: cp936 -*-import os,stringimport re#coding=utf-8# re rule,to search process PIDrule = re.compile('\s\d+\s')#www.iplaypy.com# Get the Message of the all running process and PID ProcMessage = os.popen('tasklist').readlines()# Process list to be killedKillProclist = ['PPLiveU.exe', 'wireshark.exe', 'BitCometService.exe', 'BitComet.exe', 'FTPServer.exe', 'QvodTerminal.exe', 'PPLive.exe', 'PPStream.exe', 'Uedit32.exe', 'PPSAP.exe', 'emule.exe', 'QvodPlayer.exe', 'wireshark.exe ', 'SogouCloud.exe', 'PPAP.exe', 'AcroRd32.exe' , 'firefox.exe', 'dwm.exe', 'IcbcDaemon.exe',]#Store the process name : PIDtable={}def SearchPID(temp): # To search process PID by Name '''Find Proccess Name,Return PID''' print 'Proc Name status PID' for eachline in ProcMessage: # Get a list of running process message to match for sub in temp: if eachline.find(sub)==0: # if 0 ,Find the process to be killed ret = re.search(rule,eachline) # Get the PID if ret is not None: print sub,' running ',ret.group(0) table.update({sub:ret.group(0)}) # Add {process name:PID} to the Table list # print table if table == {}: print 'No useless process is running!' return tabledef KillPID(temp): for key in temp.keys(): # Use system cmd TaskKill /T 终止指定的进程和由它启用的子进程 # /F 强制终止 # /IM 指定终止进程的映像名称 # /PID 指定要终止进程的PID cmd='TaskKill /T /F /PID %s' % (temp[key]) #print '进程名称:',key os.popen(cmd) # carry out the cmd print 'Kill process [',key,'] Successful!' if __name__=='__main__': SearchRet=SearchPID(KillProclist) KillPID(SearchRet)
编橙之家文章,
相关内容
- python中apt简单使用工具,pythonapt工具,python中apt简单
- django实现简单的数据库内容显示,django实现数据库,dj
- 动态filter查询数据Django实现方法,filterdjango,这是我在学
- Python jpg图片裁剪处理源码,,这个Python jpg
- Python实用又常用函数工具方法分享,python函数,这是我自
- Python shelve方法完成信息录入小工具源码,pythonshelve,此
- Python cookbook守护进程代码示例,pythoncookbook,关于python守
- python自动完成扫描端口使用情况示例,python自动完成
- 如何用python方法检测UDP端口,python检测udp端口,如何用
- Python调用MySQL存储过程,获得返回值示例,pythonmysql,编橙
评论关闭