QueryWorkingSet之后数一下不是shared的页个数,再乘以页大小(一般是4K)。

int main(int argc, char** argv)
{
	if (argc < 2) return 0;

	DWORD pid;
	if (sscanf(argv[1], "%d", &pid) != 1) 
		return 0;

	HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);
	if (hProc == INVALID_HANDLE_VALUE)
		return 0;

	PSAPI_WORKING_SET_INFORMATION probe;
	QueryWorkingSet(hProc, &probe, sizeof(probe));
	if (GetLastError() != ERROR_BAD_LENGTH)
		return 0;

	ULONG_PTR* data = new ULONG_PTR[probe.NumberOfEntries + 1];
	PSAPI_WORKING_SET_INFORMATION *info = (PSAPI_WORKING_SET_INFORMATION*)data;
	if (!QueryWorkingSet(hProc, info, (probe.NumberOfEntries + 1) * sizeof(ULONG_PTR)))
		return 0;

	ULONG_PTR privatePages = 0;
	for (ULONG_PTR i = 0; i < probe.NumberOfEntries; i++)
	{
		if (!info->WorkingSetInfo[i].Shared)
			privatePages++;
	}

	printf("%d %lluK", pid, privatePages * 4);
	return 0;
}