WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Process ID

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Mem Usage of a Running script


Keywords:
 DllHwnd Get Current Process ID PROCID Proc Id GetWindowThreadProcessId 

Question:

I am interested in having my script to verify how much memory it is using. If the process is higher than 12mb restart itself. This should solve a strange memory leak problem I am having due to some problems with an API I am calling.

I need memory usage of a process like I see in task manager!

Answer:

Apparently the "Mem Usage" you see in Task Manager is really the 'working set size' of the process. The working set is basically the set of physical memory pages that the process is using.

Fisrt, you would need to get the ProcessID of the running script. Then you could use tGetProcInfo from the process extender to retrieve information about the memory usage of the process...

#DefineFunction GetProcessID(h)
bb=BinaryAlloc(4)
BinaryEODSet(bb,4)
dllname=strcat(DirWIndows(1),"user32.dll")
DllCall(dllname,long:"GetWindowThreadProcessId",long:h,lpbinary:bb)
p=BinaryPeek4(bb,0)
return (p)
#endFunction

;Addextender("wproc34i.dll")
Addextender("wwprc44i.dll")
hwnd=DllHwnd("")  ; window title goes in here
procname = WinExeName("")
pid=GetProcessID(hwnd)
ret=tGetProcInfo(pid)
wss= itemextract(3,ret,@TAB)
kb_wss = wss/1024
message("Memory Usage on process %procname%",StrCat(kb_wss," KB")) 


Article ID:   W15859
File Created: 2013:04:01:09:09:04
Last Updated: 2013:04:01:09:09:04