python psutil監(jiān)控進(jìn)程實(shí)例
更新時(shí)間:2019年12月17日 14:54:20 作者:qq_3158353
今天小編就為大家分享一篇python psutil監(jiān)控進(jìn)程實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
我就廢話不多說了,直接上代碼吧!
import psutil import subprocess import os from os.path import join,getsize import re import time from subprocess import PIPE counter=0 filesize_last=0 def restart_process(): haspro = 0 all_process_name = psutil.pids(); for pid in all_process_name: pro = psutil.Process(pid) print("process_name : ",pro.name()); if(): pass if(pro.name() == "test_tdb.exe"): haspro=haspro+1 pro.kill() os.popen("E:/data/tdb/code/test_tdb.exe") break if(haspro==0): os.popen("E:/data/tdb/code/test_tdb.exe") # time.sleep(5) while(counter>=0): filesize = getsize(r"e:\log.csv") if(counter>0): if(filesize==filesize_last): print("EQUAL!") restart_process() counter=0 if(filesize!=filesize_last): print("NOT EQUAL!") counter=0 pass if(counter==0): filesize_last = filesize counter=counter+1 time.sleep(300) #p = subprocess.Popen('D:/project/server/bin/Debug/test_tdb.exe', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT); #returncode = p.poll() #while returncode is None: # line = p.stdout.readline() # returncode = p.poll() # line = line.strip() # print ('line : ',line); # print ('returncode : ',returncode); # if(line == b'Could not create log file: No such file or directory'): # pass #os.popen("D:/project/server/bin/Debug/test_tdb.exe",'r',-1) #os.system('D:/project/server/bin/Debug/test_tdb.exe') # p1=psutil.Popen(["D:/project/server/bin/Debug/test_tdb.exe"],stdout=PIPE) #process_list = psutil.get_process_list() #print("process_list : ",process_list); #all_process_name = psutil.pids(); #print("all_process_name= ",all_process_name); #for pid in all_process_name: # pro = psutil.Process(pid); #if(counter == 0): #print ('There are %.2f ' %(filesize/1024),'Kb') # # if(pro.name() == "test_tdb.exe"): # counter = counter+1 # pro.kill(); # os.popen("D:/project/server/bin/Debug/test_tdb.exe") # time.sleep(5);
以上這篇python psutil監(jiān)控進(jìn)程實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python數(shù)組復(fù)制拷貝的實(shí)現(xiàn)方法
這篇文章主要介紹了python數(shù)組復(fù)制拷貝的實(shí)現(xiàn)方法,實(shí)例分析了Python數(shù)組傳地址與傳值兩種復(fù)制拷貝的使用技巧,需要的朋友可以參考下2015-06-06pytest解讀fixtures之Teardown處理yield和addfinalizer方案
這篇文章主要為大家介紹了pytest解讀fixtures之Teardown處理yield和addfinalizer的方案實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06Python如何運(yùn)用pyaudio庫去做一個(gè)固定采樣率音頻錄制器
這篇文章主要介紹了Python如何運(yùn)用pyaudio庫去做一個(gè)固定采樣率音頻錄制器問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05python使用標(biāo)準(zhǔn)庫根據(jù)進(jìn)程名如何獲取進(jìn)程的pid詳解
Python有一套很有用的標(biāo)準(zhǔn)庫(standard library)。標(biāo)準(zhǔn)庫會隨著Python解釋器,一起安裝在你的電腦中的,所以下面這篇文章主要給大家介紹了關(guān)于python使用標(biāo)準(zhǔn)庫根據(jù)進(jìn)程名如何獲取進(jìn)程pid的相關(guān)資料,需要的朋友可以參考下。2017-10-10