Advertisement
Guest User

0ld_d0g

a guest
Feb 9th, 2010
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <psapi.h>
  4.  
  5. void PrintMemoryInfo( DWORD processID )
  6. {
  7.     HANDLE hProcess;
  8.     PROCESS_MEMORY_COUNTERS_EX pmc;
  9.    
  10.     printf( "\nProcess ID: %u\n", processID );
  11.  
  12.     hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID );
  13.  
  14.     if (NULL == hProcess) return;
  15.  
  16.     ZeroMemory(&pmc,sizeof(pmc));
  17.     if ( GetProcessMemoryInfo( hProcess, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)) )
  18.     {
  19.         printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
  20.         printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize );
  21.         printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
  22.         printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage );
  23.         printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage );
  24.         printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage );
  25.         printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage );
  26.         printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
  27.         printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );
  28.         printf( "\tPrivateUsage: 0x%08X\n", pmc.PrivateUsage );
  29.     }
  30.     CloseHandle( hProcess );
  31. }
  32.  
  33. int main( )
  34. {
  35.     DWORD aProcesses[1024], cbNeeded, cProcesses;
  36.     unsigned int i;
  37.  
  38.     if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
  39.         return 1;
  40.  
  41.     cProcesses = cbNeeded / sizeof(DWORD);
  42.  
  43.     for ( i = 0; i < cProcesses; i++ )
  44.         PrintMemoryInfo( aProcesses[i] );
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement