[THIN] Re: Limit Memory usage

  • From: Carlos Sanabria <csanabria@xxxxxxx>
  • To: thin@xxxxxxxxxxxxx
  • Date: Thu, 08 May 2003 10:07:30 -0500

Hi there,

I was intrigued by your problem and tried to figure out a way to run s
script to kill any process taking more than X amount of memory. Here it is:

--------BEGIN OF SCRIPT-------------
strComputer = "." 
maxWorkingSetSize = 20000000
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery( "select * from win32_process
where WorkingSetSize > maxWorkingSetSize" )
For Each objProcess in colProcesses
     objProcess.Terminate()
     WshShell.LogEvent 2, "Process " & objProcess.Name & " was terminated
for having a WorkingSetSize of " & objProcess.WorkingSetSize
Next
---------END OF SCRIPT---------------

Basically what the script does is list all the processes having a
WorkingSetSize greater than what ever you specify in the maxWorkingSetSize
variable in line 2 and logs any terminated processes to the Application Log.

Just copy and paste it in a .vbs file and it should work. A couple of
remarks:

- I have only tried it using WSH 5.6.
- The logging part is not very smooth since the Source for the event will
always be "WSH", this could be fixed using Sysinternals's logging tool, but
I wanted the script to be self-contained... So if anyone know a better way,
please share :-)
- When you copy ans paste it, be careful, your email client may wrap long
lines...

Hope it helps,

Carlos A. Sanabria, MCSA, CCA
IT Consultant

-----Original Message-----
From: thin-bounce@xxxxxxxxxxxxx [mailto:thin-bounce@xxxxxxxxxxxxx] On Behalf
Of TISSOT Thierry
Sent: Wednesday, May 07, 2003 11:25 AM
To: 'thin@xxxxxxxxxxxxx'
Subject: [THIN] Limit Memory usage


            Hello,

 

                        Whith MF XP FR2 under Win2K, is it possible to limit
memory usage of a process or to launch a script to kill a process if it uses
more than a memory limit defined by admin ?

 

Thanks

Thierry

 

Thierry TISSOT

Analyste d'Exploitation

02.51.83.26.62

thierry.tissot@xxxxxxxxxxxxxxxxxx 

 

SPHERIA Union Technique

Service Technique

1 bis rue Julien Videment

44200 NANTES

 



********************************************************
This Week's Sponsor - Emergent Online
EOL's Universal Printer new Features include:
Network Printing, Pagestreaming, 2400 DPI.
No Client Software Required!
http://www.go-eol.com/
**********************************************************

For Archives, to Unsubscribe, Subscribe or 
set Digest or Vacation mode use the below link:
http://thethin.net/citrixlist.cfm

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.474 / Virus Database: 272 - Release Date: 4/18/2003
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.474 / Virus Database: 272 - Release Date: 4/18/2003
 

********************************************************
This Week's Sponsor - Emergent Online
EOL's Universal Printer new Features include:
Network Printing, Pagestreaming, 2400 DPI.
No Client Software Required!
http://www.go-eol.com/
**********************************************************

For Archives, to Unsubscribe, Subscribe or 
set Digest or Vacation mode use the below link:
http://thethin.net/citrixlist.cfm

Other related posts: