Here is a QnD (Quick 'n Dirty) AutoHotkey script that watches an executable name and fires off a message box if memory usage of the process exceeds one gig. Obviously, change
firefox.exe to your required executable name.
#Persistent
ExeName := "firefox.exe"
SetTimer, MemWatcher, 10000
Return ; End of auto-execute section.
MemWatcher:
{
myMem := GetProcessMemoryInfo( ExeName )
If ( myMem > 1048576 )
{
MsgBox, 48, Alert!, Memory exceeded for %ExeName%
}
}
Return
GetProcessMemoryInfo( pName ) ; http://www.autohotkey.com/forum/post-223061.html#223061
{
Process, Exist, %pname%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
VarSetCapacity( memCounters, 40, 0 )
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, 40 )
DllCall( "CloseHandle", UInt, hProcess )
list = cb,PageFaultCount,PeakWorkingSetSize,WorkingSetSize,QuotaPeakPagedPoolUsage
,QuotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaNonPagedPoolUsage
,PagefileUsage,PeakPagefileUsage
/*
cb := NumGet( memCounters, 0, "UInt" )
PageFaultCount := NumGet( memCounters, 4, "UInt" )
PeakWorkingSetSize := NumGet( memCounters, 8, "UInt" )
WorkingSetSize := NumGet( memCounters, 12, "UInt" )
QuotaPeakPagedPoolUsage := NumGet( memCounters, 16, "UInt" )
QuotaPagedPoolUsage := NumGet( memCounters, 20, "UInt" )
QuotaPeakNonPagedPoolUsage := NumGet( memCounters, 24, "UInt" )
QuotaNonPagedPoolUsage := NumGet( memCounters, 28, "UInt" )
PagefileUsage := NumGet( memCounters, 32, "UInt" )
PeakPagefileUsage := NumGet( memCounters, 36, "UInt" )
*/
n=0
Loop, Parse, list, `,
{
n+=4
SetFormat, Float, 0.0 ; round up K
this := A_Loopfield
this := NumGet( memCounters, (A_Index = 1 ? 0 : n-4), "UInt") / 1024
; omit cb
If A_Index != 1
info .= A_Loopfield . ": " . this . " K" . ( A_Loopfield != "" ? "`n" : "" )
}
; Return "[" . pid . "] " . pname . "`n`n" . info ; for everything
Return WorkingSetSize := NumGet( memCounters, 12, "UInt" ) / 1024 ; what Task Manager shows
}