1

I want to write a cmd script to periodically empty the working set from the command prompt. For now I empty the working set in the Rammap tool from sysinternals, but that can't be run by a script.

3
  • Perhaps you should explain why you feel the need to periodically empty the working set. I've been developing for Windows since Win 3.1, and never had the need to do this from a command line (or, frankly, from within my code). There may be something much better you could do instead to fix the problem, rather than trying to find a way to kludge a solution. Commented Jul 8, 2014 at 17:15
  • 1
    I got problems when an database is synchronised. The RAM is running full and the pc stops responding. When emptying the working set periodically there is no problem. Commented Jul 8, 2014 at 17:20
  • 2
    I have need of this on a machine with terribly low resources, that windows 10 decided to jump on. Looks like the guys that did Process Hacker have our backs again with EmptyStandbyList.exe workingsets Commented Jun 20, 2018 at 13:08

1 Answer 1

1

It's probably easiest to compile something like this:

#include <iostream>
#include <windows.h>

int main(int argc, char **argv) { 
    if (argc != 2) {
        std::cerr << "Usage: min_mem <process_id>\n";
        return 1;
    }

    HANDLE process = OpenProcess(PROCESS_SET_QUOTA, false, atoi(argv[1]));
    SetProcessWorkingSetSize(process, -1, -1);
}

...and then run it in your script, something like:

mem_min 1234

...but replacing 1234 with the process ID (in decimal) of the process whose memory you want to minimize.

That said: I'd ask that this answer not be upvoted, since it's really a pretty crappy answer to a question that's basically just a gimme the codez I've been weak enough to post it, but would prefer not to get any rep for doing so.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.