This program uses the following windows API functions and structures
- CreateToolhelp32Snapshot
- GetProcessMemoryInfo
- Process32First
- Process32Next
- PROCESSENTRY32
- PROCESS_MEMORY_COUNTERS
The program list all the running processes including the PID and mem allocated for each process.
#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
#include <Psapi.h>
using namespace std;
void listAllRunningProcess();
int main()
{
listAllRunningProcess();
return 0;
}
void listAllRunningProcess()
{
PROCESSENTRY32 pe32;
PROCESS_MEMORY_COUNTERS pmc;
HANDLE hprocess;
hprocess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
GetProcessMemoryInfo(hprocess, &pmc, sizeof(pmc));
Process32First(hprocess, &pe32);
pe32.dwSize = sizeof(PROCESSENTRY32);
while(Process32Next(hprocess, &pe32))
{
cout << pe32.szExeFile << "------>"<< pe32.th32ProcessID<<"---->>"<< pe32.th32ParentProcessID;
cout <<"----------->"<< pmc.PeakWorkingSetSize<< endl;
}
}