# Solution: Kill processes when getting out of memory!



## RoutedScripter (Aug 2, 2011)

*Solution: Kill Processes when getting out of memory! (UPDATED)*

SOLVED:

http://www.mediafire.com/?jtq80zg7g85ut5i



--------------------------Original Post:
Is it possible  to kill a process when on a TASK MANAGER event or Perfmon event.

Say that i make a new custom counter in perfmon based on COMMIT CHARGE and that counter would always ran in the background.

So when the counter reaches above the limit i set in script , it launches actions , in this case kills some specified processes.




In the same time ,  i want to increase the UI-specific limit that is about this warning coming up, i think i saw it and it can be set in Registery, but i forogt so you guys can help me out in the meantime im gone.

The warning is fine, just getting rid of this annoying popup should be necessary 







And replacing it with a custom error message, or modifying this one (backup/duplicate), that would also have this exclamation point and some text but only A BIG OK button so it's like informing me, and not asking me stupid things i never want to do, and so I don't have to SPEND 3 HOURS pointing my mouse to hit the cancel button. ( well im not upset i just have enough, baring it for a long time now)



I have a great plan in my mind about the levels of low-memory increasing and even a sound alarm ! , just need to know if this is possible and then get into details what that script's has to do.


This is important to me since i don't run pagefile and many times i do photo editing (well, minor stuff) happen to get over the 6 GB RAM and ... once i just forgot , started up COH and bam 10 programs crashed and even ATI drivers.

EDIT: Oh an these popups must not have focus command, so it doesn't throw me out of the full screen aplication, the sound alarm would be a good replacement for that.


----------



## twilyth (Aug 2, 2011)

Doesn't Process Lasso do something like that?


----------



## RoutedScripter (Aug 2, 2011)

haven't tried yet , will tomorrow


EDIT: Trying now, i doubt it , but i see it has some "process limits" and schedulers


----------



## RoutedScripter (Aug 2, 2011)

I doubt this will work, since i need TOTAL commit charge , and then i need to close only specific processes.







I don't need to monitor all processes , nothing, just the total commit charge and from there i kill processes no matter anything else.

It's a wrong methodology for me, since the processes monitored are the ones getting closes so if i selected ALL possible processes on my system then all of them would close down effectively making PC to shut down lolz


----------



## twilyth (Aug 2, 2011)

Maybe I don't understand, but process watchdog lets you name any individual process you want to control.  I did this to monitor the old version of firefox and kill it once memory usage was over 1.5gig.


----------



## RoutedScripter (Aug 2, 2011)

Nope , i don't need this.


Look here , i found something http://justgeeks.blogspot.com/2009/05/monitoring-commit-charge-in-windows.html



> As it turns out WMI makes it extremely easy to do this. Below is a snippet of C# code that brings up an alert when Commit Charge > threshold.
> 
> public static void CheckCommitCharge()
> {
> ...




All i need to do is to improve the script to add more "levels" or warn , so it first warns me , and then it would close only certain processes for me which i will specify.

The processes i chosen are:
plugin-container.exe
searchIndexer.exe
jusched.exe
sidebar.exe
searchProtocolHost.exe
realsched.exe
searchFilterHost.exe
NokiaMServer.exe
ISUSPM.exe
IAStorIcon.exe


Those processes will never get over 6 GB combined , but they will clear just enough when im doing some stuff with other programes which are CRITICAL to my work and ofcourse shouldn't be killed obviously.

plugin-container.exe being the largest at over 500 MBs as it's part of the resource hog Firefox 3.6, others are update and standby services.

Those processes are not critical and Firefox can function without plugin-container which is a very unoptimized and pretty much every youtube video gets hogged in there and badly cleaned.

This is a great solution as i always have a lot of browser windows opened when im doing something else ...


EDIT:  Started a project in VC and i would be glad anyone with C# offer their tips.  If somebody knows C++ and C# and knows an better or easier way in C++ that would work too, even better.


----------



## twilyth (Aug 2, 2011)

That's out of my league.  I used the virtual memory trim function of process lasso for whole system memory management.  It says not to use it but it always worked well for me and never caused any problems.  I stopped using because I couldn't get tuned right for my purposes.  

But you're right, PL is geared more to individual processes.  It does have system wide functions too but I couldn't find anything that does what I think you want.  Sorry.


----------



## RoutedScripter (Aug 2, 2011)

I will report later what i came up with. just need to figure out C# a bit and also find examples on net.


EDIT: it's getting along nicely ... will share it when it's done


----------



## RoutedScripter (Aug 3, 2011)

So i got the info on how to disable that annoying win7 official "close programs" low-memory popup:

http://thehotfix.net/forums/index.p...-memory-dialog-box-in-windows-os/page__st__20



> For those who wish to completely disable the RADAR diagnostic module on Windows 7, to stop Windows from showing low memory dialogs and shutting programs down automatically:
> 
> Here are the registry keys that need to be taken over, and deleted:
> 
> ...




Making that into the program ... is another thing.


----------



## RoutedScripter (Aug 7, 2011)

Going fine ... , however don't know to implement this registery tweak in C#, that's gonna take some research. Couldn't find such command in MSDN


----------



## ctrain (Aug 8, 2011)

RuskiSnajper said:


> Going fine ... , however don't know to implement this registery tweak in C#, that's gonna take some research. Couldn't find such command in MSDN



doesn't seem to be a managed alternative, have to pinvoke a native function

http://pinvoke.net/default.aspx/advapi32/RegDeleteKey.html


----------



## remixedcat (Aug 8, 2011)

I use windows server 2008 and it has something built in called windows system resource manager and It does stuff like the OP said. I used to use it for IE to control bloat but I have mine set to allocate certain amounts of CPU per share currently. However I did disable it for now and will re-enable it later. 

if you have 2008/R2 it will work on those and if you use 2003 you can download a pack that has it.

for other OSes process lasso works.


----------



## twilyth (Aug 8, 2011)

I know I'm out of line probably for bringing this up, but if it's such a pain in the ass to get around this problem, wouldn't it be easier to buy more memory?  Unless you want DDR3-1600 with CAS7 or something, it's pretty damned cheap.  Just curious.  Thanks.


----------



## remixedcat (Aug 8, 2011)

They want to minimize commit charge, however you can just buy more RAM and then make the commit charge size really low like 4 or less GB. I leave mine at 6GB becuase PS uses tons of CC.


----------



## twilyth (Aug 8, 2011)

remixedcat said:


> They want to minimize commit charge, however you can just buy more RAM and then make the commit charge size really low like 4 or less GB. I leave mine at 6GB becuase PS uses tons of CC.



OK, probably a stupid question, but why?  Honestly, I've always been pretty fuzzy on what cc was anyway.  I even looked it up just now and it still doesn't make much sense to me.


----------



## remixedcat (Aug 8, 2011)

mine is like 2.6GB/6.0GB. Just having 32 Fx tabs open and MJ and one explorer window. That's why people obsess over it so much. We wanna keep it down to be easier on our HDDs. 

I I open PS it shoots up to almost 4 total. and when I work with PS for an hour it shoots up to almost 5GB!


----------



## twilyth (Aug 8, 2011)

remixedcat said:


> mine is like 2.6GB/6.0GB. Just having 32 Fx tabs open and MJ and one explorer window. That's why people obsess over it so much. We wanna keep it down to be easier on our HDDs.
> 
> I I open PS it shoots up to almost 4 total. and when I work with PS for an hour it shoots up to almost 5GB!



OK, that still doesn't tell me what it is.  The impression I'm getting is that regardless of how much memory you have, a certain amount is going to end up on the pagefile, but not to be rude, that makes even less sense than anything I could have imagined.  I thought the pagefile was only used for overflow.  I mean a lot of people get by with no pagefile at all.  I don't think it's a good idea, but it is a fact.  At the same time, I know that even with 16gig I still see the pagefile being used.  So I'm afraid I'm still quite confused.  Not that this is your problem or anything ofc.


----------



## RoutedScripter (Aug 8, 2011)

I can't just buy memory - i have 4 slots and only 2 GB are left to go (that would need replacing two 1GB sticks)

And i don't have reserved to spend for a new PC because this is more than enough what i honestly need.

Buying more ram at this point would just be estethical to suck those last percents of performance is not really worth the price, atleast for me.

If i buy ram i always buy the high quality RAM and that's not - that's probably one of the components i never heistated to doubt about "is it going to be worth it" --- because all the cheap ram is so freaking problematic.

Plus i have DDR2 so no more ram for me since DDR3 replaced with lower prices. Which means high price for DDR2


This may only happen if i ever come across an affordable yard sell of 2x2GB Corsairs somewhere ... but im not going to buy em new full price.


----------



## twilyth (Aug 8, 2011)

I guess memory prices are a lot different where you are.  Here you can get sticks of 2gig Mushkin enhanced silverline for $28 each.  So $56 total.
 Computer Hardware, Memory, Desktop Memory, DDR2 8...
But even that can be more than what you might want to spend.  I spent most of my life as a poor student so I definitely understand.

Another idea i had was to increase the size of your page file.  Do you know what it is currently set to?


----------



## RoutedScripter (Aug 8, 2011)

twilyth said:


> I guess memory prices are a lot different where you are.  Here you can get sticks of 2gig Mushkin enhanced silverline for $28 each.  So $56 total.
> Computer Hardware, Memory, Desktop Memory, DDR2 8...
> But even that can be more than what you might want to spend.  I spent most of my life as a poor student so I definitely understand.
> 
> Another idea i had was to increase the size of your page file.  Do you know what it is currently set to?



Everything in tech is more expensive here already 

Then the crappy euro spices it up also.



The point is - i don't want pagefile for a reason - other people around here mostly know my big arguments about that so i don't need to repeat it all over again.


----------



## twilyth (Aug 8, 2011)

RuskiSnajper said:


> Everything in tech is more expensive here already
> 
> Then the crappy euro spices it up also.
> 
> ...



OK, so to summarize, you don't want to use a page file on aesthetic/moral/philosophical grounds and you don't want to buy more ram.  Your prefered method of dealing with the problem is to find or write a windows hack that bypass it's low memory warning by killing specific processes you designate when the memory warning is or is about to be invoked.

Is that more or less accurate?  If it is, that's cool.  If that's what you want, then go for it.  I just need to know so I can unsubscribe from the thread.  So, thanks in advance.


----------



## qubit (Aug 8, 2011)

RuskiSnajper said:


> The point is - i don't want pagefile for a reason - other people around here mostly know my big arguments about that so i don't need to repeat it all over again.



Sorry Ruski, but this seems a weird way to run your PC and I don't get it at all.

So, you've got 6 gigs in it, which is an awful lot. However, the amount of resources needed to run your programs exceeds even this large amount of memory. So, you don't buy more RAM, but instead wanna kill off random processes? What? This sounds like a recipe for instability and disaster. :shadedshu

I'd really like to know why you're so against virtual memory. Fair enough, don't explain it all again, just point me to a post where you've explained this before and I'll gladly read it and talk with you about it.



twilyth said:


> OK, so to summarize, you don't want to use a page file on aesthetic/moral/philosophical grounds and you don't want to buy more ram.  Your prefered method of dealing with the problem is to find or write a windows hack that bypass it's low memory warning by killing specific processes you designate when the memory warning is or is about to be invoked.
> 
> Is that more or less accurate?  If it is, that's cool.  If that's what you want, then go for it.  I just need to know so I can unsubscribe from the thread.  So, thanks in advance.



As you can see, I'm not the only one who find this strange and even twilyth who helped you quite a lot here is put off in the end.

Windows, especially Win7, is designed to work with a pagefile and even if it's switched off it'll still use a stub. I dunno why, but I guess a TechNet knowledgebase article might explain it. This tells us that Windows is totally geared for it, so choking it off is a really bad idea.


----------



## RoutedScripter (Aug 9, 2011)

qubit said:


> Sorry Ruski, but this seems a weird way to run your PC and I don't get it at all.
> 
> So, you've got 6 gigs in it, which is an awful lot. However, the amount of resources needed to run your programs exceeds even this large amount of memory. So, you don't buy more RAM, but instead wanna kill off random processes? What? This sounds like a recipe for instability and disaster. :shadedshu
> 
> ...



There's nothing against Twilyth - when i found the justgeeks.com code sinppet i was geared enough i though i could try it my self since i already have VSC++ installed.


Don't worry about pagefile ... i will point you to the explanation thread so i don't have to rewrite a lot because it's  ... a lot.

There's very little people beliving me or the other guys who are also anti-pagefile.

In a quick summary: I installed windows 7 in July last year, before that i was on a test install which was very bugged i just used it to learn win7 for a few months prior that.

It was a clean install - had everything in plan - new ram - good bios settings - everything optimized and not overclocked - run memtests and prime95.

I haven't run with a pagefile for a year now ... and i haven't experienced a single crash or freeze randomly in windows. It's 100% positive things , the UI is super responsive , everything loads faster into memory , faster boot , my PC is so much stable and optimized it never way any year before since i assembled this custom machine in 2008. Mobo, PSU, and CPU stayed the same til today, everything else upgraded and sound card added (HUGE difference over integrated OMG! - and the industry says "CPUS are fast enough for sound today" - that doesn't really help nor has any sense - it's about the sound hardware quality - all those filters and chips.)

Except the purposely made freezes and crashes because i was testing Starcraft 2's memory management and found that their engine is very leaky. 


This program i am going to make will finally solve what i needed for the final touch to make it a non-issue. Which was constantly having to be aware of memory status and being careful. 

Basically - i cannot close stuff down what i need and sometimes it get's a lot - especially video and photo editing (amateur) as well as modding.

running firefox (1GB) , VCC++2010 , photoshop (2GB) , explorer windows , other programs ... in relatively rare situations it gets to the limit when i don't restart the PC for a few days - get's hooged up to 6000 MB and i just close those annoying win7 warning which is asking me to close down a program that i actually NEED . (just selects the highest working set or commit requirement exe)

Why would 6GB sound a lot - every other programming or modding geek has 8GB Ram machines and photo and video editing at 16 GB workstations.
Im actually lowest on the scale 


So ... i forget about it ... i do some more stuff , maybe friend calls me to play Company of Heroes multiplayer and ... bam the PC crashes or most of the drivers just close but Win7 kernel and important stuff apparently is very deep inside RAM ... never got a BSOD or anything erratic.

This program will run in bacground ... when ever total system memory requirements get to a set threshold it will kill user-selected processes to free up needed memory.

If you have a Pagefile of 6 GB ... that's 12 GB and in that case it's so much more memory , but why i don't like pagefile is obvious - a 100MB/s hard drive is not a substitute for 3000-6000 MB/s RAM. The whole logic around that is only as a feature to provide in low-memory environiments and other critical places where PERFORMANCE is NOT needed but rather FLEXIBILITY. I choose performance 

Windows doesn't need pagefile to operate - you can put the whole windows kernel onto the RAM even if you have pagefile enabled - by setting the registery value _DisablePagingExecutive_ to _1_.


That's that ... just let me find the links to the pagefile discussion, there is more than one thread.

Also i just neede help at the beginning because i dind't know such stuff exsited until i taken things into my hands and that's what i strive for - i don't give up easily - and if you can't find it - make it your self  (that's should apply for this what im going to do for a living heh - as far as programming goes)


Also in the recent years i disovered how many bullshit sites are there on the internet that just have no idea about the system and techinal stuff and are just popup sites that have some "3 steps to speed up PC 400%" ads spam and fake program promo sites ... there are also some genuine-looking blogs/articles with people who think they're smart but mostly when i tried to follow the instructions i realized how wrong they were. But i found many genuine stuff as well - that really takes some time to find.


----------



## ctrain (Aug 10, 2011)

disabling the page file is silly even if you have a lot of RAM.

if you think you can outsmart the OS, you're probably in for a losing battle. it was almost always do a better job managing things than you will.


----------



## yogurt_21 (Aug 10, 2011)

RuskiSnajper said:


> There's nothing against Twilyth - when i found the justgeeks.com code sinppet i was geared enough i though i could try it my self since i already have VSC++ installed.
> 
> 
> Don't worry about pagefile ... i will point you to the explanation thread so i don't have to rewrite a lot because it's  ... a lot.
> ...



to me it sounds like you're fighting with windows when you'd be much happier on linux.


----------



## RoutedScripter (Aug 12, 2011)

I was battling it before - already won over it.

And now making some stuff that'll make it even better.


The program is basically done - just debug and finishing touches


----------



## RoutedScripter (Aug 13, 2011)

yogurt_21 said:


> to me it sounds like you're fighting with windows when you'd be much happier on linux.



linux has a better implementation of pagefile - it's placed in a separate partition.


----------



## qubit (Aug 13, 2011)

RuskiSnajper said:


> linux has a better implementation of pagefile - it's placed in a separate partition.



You can configure Windows to work like this too, so it's a draw in this respect.


----------



## RoutedScripter (Aug 13, 2011)

qubit said:


> You can configure Windows to work like this too, so it's a draw in this respect.



The point is in the algorithm that pages stuff. but i have little experience with linux.

I had years ago knoppix live CD ... had to backup all files when MS had still locked folders.

And recently fiddled around with fedora for a week  ... there were other occasions but can't remember tham.


Well actually going through of that process of "getting used to " and getting to know every detail is well ... time consuming and i don't know why i didn't found better time ... lazy!


EDIT:

Hopefully this thing here will get done in a few minutes ... if all goes well.


----------



## RoutedScripter (Aug 14, 2011)

Here's a preview









Still going through some debug - but when out will still be beta.


----------



## RejZoR (Aug 14, 2011)

I've never killed a single process and i'm still using WinXP on my netbook. Killing apps is a thing of the past from the Win9x era.


----------



## RoutedScripter (Aug 14, 2011)

RejZoR said:


> I've never killed a single process and i'm still using WinXP on my netbook. Killing apps is a thing of the past from the Win9x era.



In what capacity do you think this would apply to what this thread is about ? A netbook doesn't sound it has much memory in the first playe either.

This program is used as a human failsafe - which happens to me a few times a month that i forget about how much RAM i have left - i fire up something and the screen goes black and a big "ooops" comes to my mind.

This is intended for environiments with moderate RAM (6GB is not a whole lot) and _lack_ of pagefile.


----------



## RoutedScripter (Aug 15, 2011)

Here it is http://www.mediafire.com/?jtq80zg7g85ut5i


It's still not fully debuged - sometimes it has problems closing because of running threads (and closes after the error msg time is out) So you would forcefully shut down the process if needed.

But it works and does exactly what i wanted all the time.  Ofcourse if you're rich with 16 GB ram or more ... guess not worry about it running out.


----------

