Hello guys -

Need help with a windows batch script that would kill processes by the memory usage but leave the last one. For example if i have 10 java.exe processes running i want to kill the top 9 by memory usage and leave the last one alone.

Help appreciated!

-sri

Recommended Answers

All 2 Replies

Hey there Sri.

For ending processes, you can check out the command 'taskkill' (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx?mfr=true) Your version of windows may or may not have a copy of taskkill.exe in C:\WINDOWS\system32\ ,which is the actual command itself. If not, don't fear! There's tons of copeies of batch commands just like this one online; although you might want to try to find a safe link, download it, and run it thru a virus scan; since it's an exe, you really don't know whats in it. After you found a clean version, drag it into C:\WINDOWS\system32\ and you should be able to use it! As for finding out which process is taking up the most CPU power, batch can't really do that. You can prolly use c or c++ to get access to hardware level stuff like that, and then call a system command in the script for killing a process. In c++ I think it's:

system("you system command here");

hope that helps!

Hello guys -

Need help with a windows batch script that would kill processes by the memory usage but leave the last one. For example if i have 10 java.exe processes running i want to kill the top 9 by memory usage and leave the last one alone.

Help appreciated!

-sri

That's easy!

taskkill -f -fi "PID eq xxx" -fi "MEMUSAGE gt xxxx"

The XXX in "PID" it's the Process PID (you can see it by typing TASKLIST in the cmd)
The XXX in "MEMUSAGE" it's the memory usage of the process (in KB)

"gt" meens greather than

cmd > taskkill /? for more info

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.