- 1、本文档共6页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Windows下用C语言获取进程cpu使用率_内存使用_IO情况.
Windows下用C语言获取进程cpu使用率,内存使用,IO情况
一个项目需要,特地写了这些功能的函数。?process_stat.h的内容如下:?
C代码??
/**?@file?
*?@brief?进程统计信息函数的声明?
*?@author?张亚霏?
*?@date?2009/05/03?
*?@version?0.1?
*?
*/??
#ifndef?PROCESS_STAT_H??
#define?PROCESS_STAT_H??
??
??
#ifdef?__cplusplus??
extern?C?{??
#endif??
??
????typedef?long?long???????????int64_t;??
????typedef?unsigned?long?long??uint64_t;??
??
??
????///?获取当前进程的cpu使用率,返回-1失败??
????int?get_cpu_usage();??
??
??
????///?获取当前进程内存和虚拟内存使用量,返回-1失败,0成功??
????int?get_memory_usage(uint64_t*?mem,?uint64_t*?vmem);??
??
??
????///?获取当前进程总共读和写的IO字节数,返回-1失败,0成功??
????int?get_io_bytes(uint64_t*?read_bytes,?uint64_t*?write_bytes);??
??
??
??
??
#ifdef??__cplusplus??
}??
#endif??
??
#endif/*PROCESS_STAT_H*/??
process_stat_win.c的内容如下:?
C代码??
/**?@file?
*?@brief?进程统计信息函数的实现?
*?@author?张亚霏?
*?@date?2009/05/03?
*?@version?0.1?
*?
*?部分代码来自MSDN的例子?
*?部分代码来自google?chromium项目?
*?
*?需要连接到psapi.lib?
*/??
??
??
#include?windows.h??
#include?psapi.h??
#include?assert.h??
#include?process_stat.h??
??
??
??
///?时间转换??
static?uint64_t?file_time_2_utc(const?FILETIME*?ftime)??
{??
????LARGE_INTEGER?li;??
??
????assert(ftime);??
????li.LowPart?=?ftime-dwLowDateTime;??
????li.HighPart?=?ftime-dwHighDateTime;??
????return?li.QuadPart;??
}??
??
??
///?获得CPU的核数??
static?int?get_processor_number()??
{??
????SYSTEM_INFO?info;??
????GetSystemInfo(info);??
????return?(int)info.dwNumberOfProcessors;??
}??
??
??
??
??
int?get_cpu_usage()??
{??
????//cpu数量??
????static?int?processor_count_?=?-1;??
????//上一次的时间??
????static?int64_t?last_time_?=?0;??
????static?int64_t?last_system_time_?=?0;??
??
??
????FILETIME?now;??
????FILETIME?creation_time;??
????FILETIME?exit_time;??
????FILETIME?kernel_time;??
????FILETIME?user_time;??
????int64_t?system_time;??
????int64_t?time;??
????int64_t?system_time_delta;??
????int64_t?time_delta;??
??
????int?cpu?=?-1;??
??
??
????if(processor_count_?==?-1)??
????{??
????????processor_count_?=?get_processor_number();??
????}??
??
????GetSystemTimeAsFile
您可能关注的文档
- WindowsServer2003群集指南..doc
- windowsserver2008终端服务安装激活方法..doc
- Windowsserver2008系统基础优化技巧..doc
- windowsserver2008设置多用户同时远程登录..doc
- WindowsServer2008配置NLB..docx
- Windowsserver2008部署站点到站点的VPN..doc
- WindowsServer常用端口..doc
- WindowsWIN_7快捷键大全(电脑高手用)..doc
- Windowssever2003资源共享与访问权限..doc
- windowsserver2008远程桌面(授权普通用户登录)~..docx
- 第17课 明朝的灭亡和清朝的建立 巩固练习 2024-2025学年下期初中历史统编版七年级下.docx
- 人教版(2019)必修三 Unit 1 Festivals and Celebrations Lis.pptx
- 人教版(2019)必修三 Unit 3 Diverse Cultures Reading for W.pptx
- 人教版(2019) 必修第一册 Unit 1 Teenage Life Reading and.pptx
- 人教版(2019)必修第一册Unit 2 Travelling Around Reading and.pptx
- 六年级单元作文复习.pptx
- 【作文写作法则】(初中语文)第10讲 常考应用文写作模板 学案.doc
- Unit 8 Once upon a Time 重点语法 专题练 2024-2025学.docx
- 人教版(2019)必修第一册Unit 3 Sports and fitness Reading fo.pptx
- 期末综合模拟试题 2024-2025学年下期初中道德与法治统编版八年级下册 (1).docx
文档评论(0)