首页 > Windows开发 > 详细

windows系统调用 进程快照

时间:2014-05-17 18:10:58      阅读:615      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 #include "windows.h"
 2 #include "tlhelp32.h"
 3 #include "iostream"
 4 using namespace std;
 5 
 6 #pragma comment(lib,"kernel32.lib")
 7 
 8 DWORD GetKernelModePercentage(const FILETIME& ftKernel,
 9                               const FILETIME& ftUser
10                               ){
11                                  ULONGLONG qwKernel=(((ULONGLONG)ftKernel.dwHighDateTime)<<32)+ftKernel.dwLowDateTime;
12                                  ULONGLONG qwUser=(((ULONGLONG)ftUser.dwHighDateTime)<<32)+ftUser.dwLowDateTime;
13                                  ULONGLONG qwTotal=qwKernel+qwUser;
14                                  DWORD dwPct=(DWORD)(((ULONGLONG)100*qwKernel)/qwTotal);
15                                  return (dwPct);
16 
17 
18 }
19 
20 void main(){
21     HANDLE hSnapshot=CreateToolhelp32Snapshot(
22         TH32CS_SNAPPROCESS,
23         0
24         );
25 
26     PROCESSENTRY32 pe;
27 
28     ZeroMemory(&pe,sizeof(pe));
29     pe.dwSize=sizeof(pe);
30 
31     BOOL bMore=Process32First(hSnapshot,&pe);
32 
33     while(bMore){
34         HANDLE hProcess=OpenProcess(
35             PROCESS_QUERY_INFORMATION,
36             FALSE,
37             pe.th32ProcessID
38             );
39 
40         if(hProcess!=NULL){
41             FILETIME ftCreation,ftKernelMode,ftUserMode,ftExit;
42             GetProcessTimes(
43                 hProcess,
44                 &ftCreation,
45                 &ftExit,
46                 &ftKernelMode,
47                 &ftUserMode    );
48 
49         DWORD dwPctKernel=GetKernelModePercentage(
50             ftKernelMode,
51             ftUserMode
52             );
53 
54         cout<<"process ID:"<<pe.th32ProcessID
55             <<",EXE file:"<<pe.szExeFile
56             <<",% in Kernel mode:"<<dwPctKernel<<endl;
57 
58         CloseHandle(hProcess);
59         }
60         bMore=Process32Next(hSnapshot,&pe);
61     }
62 
63 
64     getchar();
65 }
bubuko.com,布布扣

 

windows系统调用 进程快照,布布扣,bubuko.com

windows系统调用 进程快照

原文:http://www.cnblogs.com/593213556wuyubao/p/3732626.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!