Click here to Skip to main content
15,889,843 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: simple program Pin
David Crow21-Mar-05 4:30
David Crow21-Mar-05 4:30 
GeneralRe: simple program Pin
mpapeo21-Mar-05 8:45
mpapeo21-Mar-05 8:45 
GeneralCSocket & closed connection Pin
pand_pl20-Mar-05 3:34
pand_pl20-Mar-05 3:34 
GeneralRe: CSocket & closed connection Pin
eli1502197920-Mar-05 4:40
eli1502197920-Mar-05 4:40 
GeneralRe: CSocket & closed connection Pin
pand_pl20-Mar-05 5:23
pand_pl20-Mar-05 5:23 
GeneralRe: CSocket & closed connection Pin
eli1502197920-Mar-05 21:04
eli1502197920-Mar-05 21:04 
GeneralRe: CSocket & closed connection Pin
pand_pl21-Mar-05 1:57
pand_pl21-Mar-05 1:57 
GeneralProcess memory Usage Pin
zan yan20-Mar-05 2:27
zan yan20-Mar-05 2:27 
I want to get memory usage information of one process.
Looking at the old threads, I have been told to execute the following codes.

#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 (NULL == hProcess)
return;

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[i] );
}

then create a console application, copy above code, compile and run.
my question is :
when runing the program , one condition function OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, processID ) return NULL, the other condition function GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) return FALSE, so I can't get anything about the memory usage information per process.

can anyone help ?
GeneralRe: Process memory Usage Pin
Aamir Butt21-Mar-05 0:35
Aamir Butt21-Mar-05 0:35 
GeneralRe: Process memory Usage Pin
David Crow21-Mar-05 4:38
David Crow21-Mar-05 4:38 
GeneralNeed uuid.lib for Visual Studio 6 (debug) Pin
lob19-Mar-05 23:56
lob19-Mar-05 23:56 
GeneralRe: Need uuid.lib for Visual Studio 6 (debug) Pin
Verolix20-Mar-05 6:22
Verolix20-Mar-05 6:22 
GeneralRe: Need uuid.lib for Visual Studio 6 (debug) Pin
lob20-Mar-05 23:10
lob20-Mar-05 23:10 
Questionhow can I post WM_UNICHAR message Pin
pavel070519-Mar-05 22:11
pavel070519-Mar-05 22:11 
AnswerRe: how can I post WM_UNICHAR message Pin
PJ Arends20-Mar-05 16:20
professionalPJ Arends20-Mar-05 16:20 
GeneralRe: how can I post WM_UNICHAR message Pin
pavel070520-Mar-05 19:17
pavel070520-Mar-05 19:17 
GeneralRe: how can I post WM_UNICHAR message Pin
ThatsAlok20-Mar-05 19:34
ThatsAlok20-Mar-05 19:34 
GeneralRe: how can I post WM_UNICHAR message Pin
pavel070520-Mar-05 20:21
pavel070520-Mar-05 20:21 
GeneralRe: how can I post WM_UNICHAR message Pin
ThatsAlok20-Mar-05 22:08
ThatsAlok20-Mar-05 22:08 
GeneralCompile errors Pin
steven1119-Mar-05 21:47
steven1119-Mar-05 21:47 
GeneralRe: Compile errors Pin
Mike Dimmick19-Mar-05 22:43
Mike Dimmick19-Mar-05 22:43 
GeneralRe: Compile errors Pin
steven1119-Mar-05 23:54
steven1119-Mar-05 23:54 
GeneralRe: Compile errors Pin
Michael Dunn20-Mar-05 5:56
sitebuilderMichael Dunn20-Mar-05 5:56 
GeneralRe: Compile errors Pin
steven1120-Mar-05 8:35
steven1120-Mar-05 8:35 
GeneralRe: Compile errors Pin
steven1120-Mar-05 8:52
steven1120-Mar-05 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.