GetProcessWorkingSetSize function

Retrieves the minimum and maximum working set sizes of the specified process.

Syntax

C++
BOOL WINAPI GetProcessWorkingSetSize(
  _In_   HANDLE hProcess,
  _Out_  PSIZE_T lpMinimumWorkingSetSize,
  _Out_  PSIZE_T lpMaximumWorkingSetSize
);

Parameters

hProcess [in]

A handle to the process whose working set sizes will be obtained. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights1.

Windows Server 2003 and Windows XP:  The handle must have the PROCESS_QUERY_INFORMATION access right.
lpMinimumWorkingSetSize [out]

A pointer to a variable that receives the minimum working set size of the specified process, in bytes. The virtual memory manager attempts to keep at least this much memory resident in the process whenever the process is active.

lpMaximumWorkingSetSize [out]

A pointer to a variable that receives the maximum working set size of the specified process, in bytes. The virtual memory manager attempts to keep no more than this much memory resident in the process whenever the process is active when memory is in short supply.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError2.

Remarks

The "working set" of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. The minimum and maximum working set sizes affect the virtual memory paging behavior of a process.

Examples

C++
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    SIZE_T  dwMin, dwMax;
    HANDLE hProcess;

    if (argc != 2)
    {
        printf("This program requires a process ID as an argument.\n");
        return 1;
    }

    // Retrieve a handle to the process.

    hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, 
                            FALSE, atoi(argv[1]));
     if (!hProcess)
    {
        printf( "OpenProcess failed (%d)\n", GetLastError() );
        return 1;
    }

    // Retrieve the working set size of the process.

    if (!GetProcessWorkingSetSize(hProcess, &dwMin, &dwMax))
    {
        printf("GetProcessWorkingSetSize failed (%d)\n",
            GetLastError());
        return 1;
    }

    printf("Process ID: %d\n", atoi(argv[1]));
    printf("Minimum working set: %lu KB\n", dwMin/1024);
    printf("Maximum working set: %lu KB\n", dwMax/1024);

    CloseHandle(hProcess);

    return 0;
}


Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Process Working Set3 Processes4 SetProcessWorkingSetSize5

 

 

Send comments about this topic to Microsoft6

Build date: 10/16/2012

连接资料表
1 http://msdn.microsoft.com/zh-cn/library/ms684880.aspx
2 http://msdn.microsoft.com/zh-cn/library/ms679360.aspx
3 http://msdn.microsoft.com/zh-cn/library/ms684891.aspx
4 http://msdn.microsoft.com/zh-cn/library/ms682015.aspx
5 http://msdn.microsoft.com/zh-cn/library/ms686234.aspx
6 Send comments about this topic to Microsoft; mailto:wsddocfb@microsoft.com?subject=Documentation%20feedback%20%5Bprocthread%5Cbase%5D:%20GetProcessWorkingSetSize%20function%20%20RELEASE:%20(10/16/2012)&body=%0A%0APRIVACY%20STATEMENT%0A%0AThe%20doc%20team%20uses%20your%20feedback%20to%20improve%20the%20documentation.%20We%20don't%20use%20your%20email%20address%20for%20any%20other%20purpose.%20We'll%20remove%20your%20email%20address%20from%20our%20system%20after%20the%20issue%20that%20you%20are%20reporting%20is%20resolved.%20While%20we%20are%20working%20to%20resolve%20this%20issue,%20we%20may%20send%20you%20an%20email%20message%20to%20request%20more%20info%20about%20your%20feedback.%20After%20the%20issue%20is%20addressed,%20we%20may%20send%20you%20an%20email%20message%20to%20let%20you%20know%20that%20your%20feedback%20has%20been%20addressed.%0A%0AFor%20more%20info%20about%20Microsoft's%20privacy%20policy,%20see%20http://privacy.microsoft.com/en-us/default.aspx.