- 论坛徽章:
- 0
|
我的exe文件怎么总是空啊?平台是win2K,GCC编译的
代码如下:
struct map_value
{
char mapName[MAX_PATH];
double cpuUsage;
};
map<DWORD,map_value*>; oldProcessTime;
typedef map<DWORD,map_value*>;::value_type valuetype;
map_value my_map;
struct map_value my_dismap;
map<DWORD,map_value*>;::iterator oldIt;
int ncount=0;
HANDLE snapshot;
PROCESSENTRY32 processinfo;
processinfo.dwSize = sizeof (processinfo) ;
snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(snapshot==NULL)
return;
bool stat = Process32First (snapshot, &processinfo) ;
while (stat)
{
ncount=ncount+1;
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, processinfo.th32ProcessID );
if ( hProcess )
{
FILETIME CreationTime,ExitTime,KernelTime,UserTime;
GetProcessTimes (hProcess,&CreationTime,&ExitTime,&KernelTime,&UserTime);
*(__int64*)(&LUserTime)=*(__int64*)(&UserTime);
*(__int64*)(&LKernelTime)=*(__int64*)(&KernelTime);
my_map.cpuUsage=Li2Double(LUserTime)+Li2Double(LKernelTime);
strcpy(my_map.mapName,processinfo.szExeFile);
oldIt=oldProcessTime.find(processinfo.th32ProcessID);
if( oldIt!=oldProcessTime.end() ) //判断如果有pid
{
。。。。。。。
}
else
{
//插入一个新值
oldProcessTime.insert(valuetype(processinfo.th32ProcessID,&my_map));
}
}
stat = Process32Next (snapshot, &processinfo) ;
}
for(oldIt=oldProcessTime.begin();oldIt!=oldProcessTime.end();oldIt++)
{
printf("%-20d%-20f%-20s\n",(*oldIt).first,(*oldIt).second->;cpuUsage,(*oldIt).second->;cpuUsage);
}
结果如下:
8 1301872.000000 (null)
160 1301872.000000 (null)
204 1301872.000000 (null)
232 1301872.000000 (null)
244 1301872.000000 (null)
324 1301872.000000 (null)
428 1301872.000000 (null)
464 1301872.000000 (null)
492 1301872.000000 (null)
596 1301872.000000 (null)
608 1301872.000000 (null)
656 1301872.000000 (null)
688 1301872.000000 (null)
744 1301872.000000 (null)
800 1301872.000000 (null)
832 1301872.000000 (null)
868 1301872.000000 (null)
880 1301872.000000 (null)
928 1301872.000000 (null)
956 1301872.000000 (null)
976 1301872.000000 (null)
1008 1301872.000000 (null)
1032 1301872.000000 (null)
1316 1301872.000000 (null)
1328 1301872.000000 (null)
1344 1301872.000000 (null)
1444 1301872.000000 (null)
1468 1301872.000000 (null)
1528 1301872.000000 (null)
1604 1301872.000000 (null)
1772 1301872.000000 (null)
1788 1301872.000000 (null)
1880 1301872.000000 (null)
1948 1301872.000000 (null)
2140 1301872.000000 (null)
2268 1301872.000000 (null)
2724 1301872.000000 (null)
3064 1301872.000000 (null)
3676 1301872.000000 (null) |
|