How Can Get A Process Memory Usage BY PID

  • Thread starter Thread starter r2du-soft
  • Start date Start date
R

r2du-soft

Guest
i tried find a process memory usage by pid number


#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#include <iostream>
using namespace std;


int main(void)
{

DWORD Process_PID = 7540;
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS_EX PCM;
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, Process_PID);
if (GetProcessMemoryInfo(hProcess, (PROCESS_MEMORY_COUNTERS *)&PCM, sizeof(PCM)))
{
cout << PCM.WorkingSetSize << " IS WorkingSetSize";
cout << endl;

cout << PCM.PrivateUsage << " IS PrivateSetSize";
cout << endl;

cout << (PCM.PrivateUsage - PCM.WorkingSetSize) / 1024 << " KB";
cout << endl;
}

}



But i the return value is different value of task manager that process memory usage...


Which part of my calculation is wrong?

thanks

Continue reading...
 
Back
Top