用C语言监控一个进程(比如QQ)的内存占用情况,整合了网上的一些代码。
头文件"process_stat.h"
#ifndef PROCESS_STAT_H
#define PROCESS_STAT_H
#ifdef __cplusplus
extern "C" {
#endif
typedef long long int64_t;
typedef unsigned long long uint64_t;
#ifdef __cplusplus
}
#endif
#endif/*PROCESS_STAT_H*/
主函数
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <psapi.h>
#include <assert.h>
#include "process_stat.h"
#include "tlhelp32.h "
UINT GetProcessIdByName(LPCTSTR pszExeFile)
{
UINT nProcessID = 0;
PROCESSENTRY32 pe = {sizeof(PROCESSENTRY32)};
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
if (hSnap