如何查看一个进程消耗多少内存,占用多少cpu?并将这些数据输出到一个文档中,请高手不吝赐教

9527cba 2007-04-27 07:40:18
如题,哪位大侠伸伸手,小弟着急啊!

有没有什么合适的软件,不要多大的功能的,只要能够如查看一个进程消耗多少内存,占用多少cpu,并将这些数据输出到一个文档中,就可以了.
...全文
1558 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
lin_style 2007-04-28
  • 打赏
  • 举报
回复
学习。
yuyunliuhen 2007-04-28
  • 打赏
  • 举报
回复
mark
qihui_zhu 2007-04-28
  • 打赏
  • 举报
回复
.
charleswu82 2007-04-28
  • 打赏
  • 举报
回复
mark
lauxp 2007-04-28
  • 打赏
  • 举报
回复
系统调用而已,问题是你在什么OS上面?
yoyo_alex_lw 2007-04-28
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WIN32COM.v10.en/perfmon/base/collecting_memory_usage_information_for_a_process.htm

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

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.
9527cba 2007-04-28
  • 打赏
  • 举报
回复
wanfustudio(雁南飞:知识之败,慕虚名而不务潜修也) 这个程序只有显示CPU的,内存的没有啊文件记录也没有。。。 你那个内存的函数只定义了没有用到啊
Benny_ywb 2007-04-28
  • 打赏
  • 举报
回复
vc 6.0真得不好使阿
9527cba 2007-04-28
  • 打赏
  • 举报
回复
呵呵,找到原因了:

Windows子系统设置错误, 提示:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Windows项目要使用Windows子系统, 而不是Console, 可以这样设置:
[Project] --> [Settings] --> 选择"Link"属性页,
在Project Options中将/subsystem:console改成/subsystem:windows
9527cba 2007-04-28
  • 打赏
  • 举报
回复
还是有错误

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Get428.exe : fatal error LNK1120: 1 unresolved externals


这个是为什么?这个连接错误应该怎样改?
walkingstick 2007-04-28
  • 打赏
  • 举报
回复
mark~~~~~~
飞哥 2007-04-28
  • 打赏
  • 举报
回复
while(!_kbhit())

随便按下键盘,就退出来了
dai_weitao 2007-04-28
  • 打赏
  • 举报
回复
MSDN自己查查吧. 简单的API调用而已.
9527cba 2007-04-28
  • 打赏
  • 举报
回复
换了个方式,好了。

谢谢各位哈,给分啦!
9527cba 2007-04-28
  • 打赏
  • 举报
回复
Link error:

1.obj : error LNK2001: unresolved external symbol _GetProcessMemoryInfo@12
Debug/Myget.exe : fatal error LNK1120: 1 unresolved externals
9527cba 2007-04-28
  • 打赏
  • 举报
回复
unresolved external symbol _GetProcessMemoryInfo@12
seas110 2007-04-28
  • 打赏
  • 举报
回复
学习~
9527cba 2007-04-27
  • 打赏
  • 举报
回复
我添加了lib和.h ,可以运行了,可是死循环那里了

我不懂那个Process方面的API,是不是你while(!_kbhit())那里死循环了?
飞哥 2007-04-27
  • 打赏
  • 举报
回复
没装SDK吧


程序肯定是没错的


9527cba 2007-04-27
  • 打赏
  • 举报
回复
另:OS: WinXP IDE: Microsoft Visual C++ 6.0
加载更多回复(8)

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧