-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_getData.py
More file actions
33 lines (30 loc) · 1.01 KB
/
_getData.py
File metadata and controls
33 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This Python file uses the following encoding: utf-8
import sys
import time
import psutil
import pandas as pd
timeout = time.time() + 20
alertFile = "alertFile.alert"
while (True):
try:
pids = psutil.pids()
procs = []
for pid in pids:
try:
temp = psutil.Process(pid)
if len(temp.exe()) == 0:
procs.append([str(pid),temp.name(),temp.status(),"---"])
else:procs.append([str(pid),temp.name(),temp.status(),str(temp.exe())])
except:pass
df = pd.DataFrame(data=procs, columns=['Pid','Name','Status','ExePath'])
time.sleep(3)
if time.time() > timeout:
break
df.to_csv (r'getData.csv', index = False, header=True)
except:
try:
with open(alertFile, "a") as alertF:
alertF.write("{} - get_size - {}\n".format(dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), error))
except:
pass
sys.exit(0)