return i; }你可以在中间加一个 GetProcessTimes The GetProcessTimes function obtains timing information about a specified process. BOOL GetProcessTimes( HANDLE hProcess, // specifies the process of interest LPFILETIME lpCreationTime, // when the process was created LPFILETIME lpExitTime, // when the process exited LPFILETIME lpKernelTime, // time the process has spent in kernel // mode LPFILETIME lpUserTime // time the process has spent in user mode );
我主页上有个副本。
http://asp.6to23.com/nowcan/tech/proc_cpu.htm内存嘛,不会了。
了解一个应用程序在运行过程中实际向它交付了多大容量的内存
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hProcess Long,指定一个进程的句柄
lpMinimumWorkingSetSize Long,用于装载最小进程容量的一个变量
lpMaximumWorkingSetSize Long,用于装载最大进程容量的一个变量
适用平台
Windows NT
GetTheardTimes
获取与一个线程的经过时间有关的信息
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hThread Long,一个线程句柄
lpCreationTime FILETIME,指定一个FILETIME结构,在其中装载线程的创建时间
lpExitTime FILETIME,指定一个FILETIME结构,在其中装载线程的中止时间
lpKernelTime FILETIME,指定一个FILETIME结构,在其中装载线程花在内核模式上的总时间
lpUserTime FILETIME,指定一个FILETIME结构,在其中装载线程花在用户模式上的总时间
适用平台
Windows NT
{
PROCESS_MEMORY_COUNTERS MemoryInfo;
PROCESSENTRY32 ProcessEntry32;
HANDLE hProcess;
HANDLE hSnapshot;
int i = 0;
BOOL ret = TRUE; hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
Process32First(hSnapshot, &ProcessEntry32);
while(ret)
{
lstrcpy(m_ProcessInfoList[i].cFileName, ProcessEntry32.szExeFile);
m_ProcessInfoList[i].uPID = ProcessEntry32.th32ProcessID;
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessEntry32.th32ProcessID); GetProcessMemoryInfo(hProcess, &MemoryInfo, sizeof(PROCESS_MEMORY_COUNTERS)); m_ProcessInfoList[i].uMemory = MemoryInfo.WorkingSetSize / 1024; ret = Process32Next(hSnapshot, &ProcessEntry32);
i++;
}
return i;
}你可以在中间加一个
GetProcessTimes
The GetProcessTimes function obtains timing information about a specified process. BOOL GetProcessTimes(
HANDLE hProcess, // specifies the process of interest
LPFILETIME lpCreationTime, // when the process was created
LPFILETIME lpExitTime, // when the process exited
LPFILETIME lpKernelTime, // time the process has spent in kernel
// mode
LPFILETIME lpUserTime // time the process has spent in user mode
);
但这种方法不获得pid = 0的信息,可能是权限不够,我还没解决