如何得到一过进程的地址(即运行该进程的内成块的起始和终止地址)(200分)

  • 主题发起人 主题发起人 sim_might
  • 开始时间 开始时间
S

sim_might

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到一过进程的地址(即运行该进程的内成块的起始和终止地址)
 
Get From MSDN


Collecting Memory Usage Information For a Process
To determine the efficiency of your application, you may want to examine its memory usage. The following sample code uses the GetProcessMemoryInfo function to obtain information about the memory usage of a process.

#include <windows.h>
#include <stdio.h>
#include "psapi.h"

void PrintMemoryInfo( DWORD processID )
{
; ; HANDLE hProcess;
; ; PROCESS_MEMORY_COUNTERS pmc;

; ; // Print the process identifier.

; ; printf( "/nProcess ID: %u/n", processID );

; ; // Print information about the memory usage of the process.

; ; hProcess = OpenProcess( ;PROCESS_QUERY_INFORMATION |
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; PROCESS_VM_READ,
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; FALSE, processID );

; ; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
; ; {
; ; ; ; printf( "/tPageFaultCount: 0x%08X/n", pmc.PageFaultCount );
; ; ; ; printf( "/tPeakWorkingSetSize: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.PeakWorkingSetSize );
; ; ; ; printf( "/tWorkingSetSize: 0x%08X/n", pmc.WorkingSetSize );
; ; ; ; printf( "/tQuotaPeakPagedPoolUsage: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.QuotaPeakPagedPoolUsage );
; ; ; ; printf( "/tQuotaPagedPoolUsage: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.QuotaPagedPoolUsage );
; ; ; ; printf( "/tQuotaPeakNonPagedPoolUsage: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.QuotaPeakNonPagedPoolUsage );
; ; ; ; printf( "/tQuotaNonPagedPoolUsage: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.QuotaNonPagedPoolUsage );
; ; ; ; printf( "/tPagefileUsage: 0x%08X/n", pmc.PagefileUsage );
; ; ; ; printf( "/tPeakPagefileUsage: 0x%08X/n",
; ; ; ; ; ; ; ; ; pmc.PeakPagefileUsage );
; ; }

; ; CloseHandle( hProcess );
}

void main( )
{
; ; // Get the list of process identifiers.

; ; DWORD aProcesses[1024], cbNeeded, cProcesses;
; ; unsigned int i;

; ; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
; ; ; ; return;

; ; // Calculate how many process identifiers were returned.

; ; cProcesses = cbNeeded / sizeof(DWORD);

; ; // Print the memory usage for each process

; ; for ( i = 0; i < cProcesses; i++ )
; ; ; ; PrintMemoryInfo( aProcesses );
}
The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintMemoryInfo function, passing the process identifier. PrintMemoryInfo in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows only the process identifier. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Finally, PrintMemoryInfo calls the GetProcessMemoryInfo function to obtain the memory usage information.
 
接受答案了.
 

Similar threads

D
回复
0
查看
928
DelphiTeacher的专栏
D
D
回复
0
查看
883
DelphiTeacher的专栏
D
后退
顶部