[python-win32] Re: Memory Usage for Processes
Tom Haddon
thaddon at equilar.com
Fri Feb 11 03:15:44 CET 2005
Sorry, a little quick on the trigger there.
I have it working as below (as you can see this is just testing code).
I'm now having trouble retrieving the name of the process. I'm trying:
win32process.GetModuleFileNameEx(handle, <MODULE HANDLE>)
The module handle is escaping me. I've tried using the win32con.PROCESS_QUERY_INFORMATION, and then I've tried iterating through integers from 1 to 100,000 to be sure, but no dice. Am I missing something?
import win32process
import win32con
import win32api
class WinProcesses:
def __init__(self):
pass
def listprocesses(self):
for process in self.proclist():
try:
han = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, 0, process)
except:
han = ""
if han != "":
procmeminfo = self.meminfo(han)
procmemusage = (procmeminfo["WorkingSetSize"]/1024)
print "PID: %s Mem: %sK" % (process, procmemusage)
def proclist(self):
return win32process.EnumProcesses()
def meminfo(self, handle):
return win32process.GetProcessMemoryInfo(handle)
if __name__=="__main__":
processes = WinProcesses()
test = processes.listprocesses()
print test
-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of Roger Upole
Sent: Thursday, February 10, 2005 4:51 PM
To: python-win32 at python.org
Subject: [python-win32] Re: Memory Usage for Processes
You'll need to specify more access in OpenProcess.
It's 1 now, which is only PROCESS_TERMINATE.
Most likely you're getting an access denied in the
GetProcessMemoryInfo call. (This is why a bare except:
is not generally a good thing to do) Try changing the access mode to
win32con.PROCESS_QUERY_INFORMATION|win32con.PROCESS_VM_READ.
hth
Roger
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list