0

I want to use SetProcessWorkingSetSize function, and on MSDN i see this:

"The handle must have the PROCESS_SET_QUOTA access right. For more information, see Process Security and Access Rights."

So, how can i set PROCESS_SET_QUOTA to process handle?

I want to write program that runs executable with working set limits, so there is main piece of code:

STARTUPINFO si;
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);
    GetStartupInfo(&si);
    si.dwFlags = 0;
    PROCESS_INFORMATION pi;

if (!CreateProcess(
        exePath.c_str(),
        cmdParametersBuffer,
        NULL,
        NULL,
        FALSE,
        NORMAL_PRIORITY_CLASS,
        NULL,
        NULL,
        &si,
        &pi))
    {
     cout << "error" << endl;
    }
SetProcessWorkingSetSize(pi.hProcess, 20 * 4 * 1024, 100*1024*1024);
3
  • Must downvote, net is full of examples how to enable or disable privilegies. Commented Apr 8, 2014 at 13:16
  • 2
    For example snippet from MSDN: msdn.microsoft.com/en-us/library/windows/desktop/… Commented Apr 8, 2014 at 13:21
  • As i understand this example can change priveleges of existing objects. The question is how to set privelege to process that creating by CreateProcess. So, i can't find any answer in net, sorry. Can you help me with this? Commented Apr 8, 2014 at 13:47

2 Answers 2

2

Did you actually try the code you have showed and it is not working for you? If so, what error is GetLastError() reporting?

If you read the documentation, it says:

Process Security and Access Rights

PROCESS_ALL_ACCESS
All possible access rights for a process object.
...
The handle returned by the CreateProcess function has PROCESS_ALL_ACCESS access to the process object

So you should be able to call SetProcessWorkingSetSize() after CreateProcess() exits, exactly like you have showed, without doing anything extra to enable PROCESS_SET_QUOTA rights, as it should already be enabled.

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

3 Comments

Hi, thanks for answer. GetLastError returns 0 I just write this thest app ideone.com/VqjrwL and run it using this code example, but did'nt get any notifications or error messages. so all works like i don't set any limit
so i set working set size to 100 Mb, but in app allocates 1Gb without no errors or notifications.
So, can you help me with this?
0

Your example code is calling SetProcessWorkingSetSize() successfully, as the error you get is 0. If you got an error like 0x522 ERROR_PRIVILEGE_NOT_HELD then you'd know the call failed.

It might help to know that an app is expected to be able to allocate more memory than its the working set size. The OS will page out memory from RAM. If you use Task Manager to view the Working Set for your process, is it actually exceeding the quota you set?

You might also need to use SetProcessWorkingSetSizeEx wth flag QUOTA_LIMITS_HARDWS_MAX_ENABLE to force the OS to actually apply your setting.

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.