0
I have a script that captures all processes from the machine, using the library PSUTIL, But when you put it inside an array it is only saving the last value in memory, not all values.
OBS: I need the values within an array to make comparisons
If someone identifies the error, it will be of great help :)
import psutil, datetime
cpu_count = psutil.cpu_count()
process = []
for pid in psutil.pids():
try:
p = psutil.Process(pid)
name = p.name() # execute internal routine once collecting multiple info
time = p.cpu_times() # return cached value
mem_percent = p.memory_percent(memtype="rss") # return cached value
cpu_percent = p.cpu_percent(interval=1) / cpu_count # return cached value
create_time = p.create_time() # return cached value
pid = p.ppid() # return cached value
status = p.status() # return cached value
except: continue
process = [''+str(pid)+'',''+str(name)+'',''+str(cpu_percent)+'',''+str(mem_percent)+'',''+str(datetime.datetime.fromtimestamp(create_time).strftime("%Y-%m-%d %H:%M:%S"))+'',''+str(time)+'',''+str(status)+'']
for i in range(len(process)):
print(process[i])
Thank you very much!
– Luis Henrique