-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcInfo.py
34 lines (27 loc) · 927 Bytes
/
ProcInfo.py
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
34
"""
Design automation script which display information of running processes as its name, PID,
Username.
"""
import time;
import psutil;
def processLogger():
listProcess=[];
logfile="RunningProcesses.log";
with open(logfile,'w') as fobj:
separator="-"*80;
fobj.write(separator + "\nProcess Logger : " + str(time.ctime()) + "\n" + separator + "\n" );
for pro in psutil.process_iter():
try:
pinfo=pro.as_dict(attrs=['pid','name','username']);
listProcess.append(pinfo);
except (psutil.NoSuchProcess,psutil.AccessDenied,psutil.ZombieProcess):
pass;
for element in listProcess:
fobj.write("%s\n"%element);
def main():
try:
processLogger();
except Exception as E:
print("Exception occured: ",E);
if __name__ == "__main__":
main();