?? process.cpp
字號(hào):
#include <iostream>
#include<windows.h>
using namespace std;
int main()
{
SIZE_T n1,n2,n3,m_uiCpuTime;
SYSTEMTIME st1,st2;
FILETIME ft1,ft2,ft3,ft4;
HANDLE hProcess;
STARTUPINFO si; //一些必備參數(shù)設(shè)置
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION pi; //必備參數(shù)設(shè)置結(jié)束
if(!CreateProcess(NULL,"cmd.exe",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) //"cmd.exe"是您要運(yùn)行的程序的路徑
{
cout<<"Create Fail!"<<endl;
exit(1);
}
else
{
hProcess=GetCurrentProcess();
// 獲得進(jìn)程使用的CPU時(shí)間(WINDOWS的任務(wù)管理器使用的是 內(nèi)核時(shí)間+用戶時(shí)間)
if(GetProcessTimes(hProcess,&ft1,&ft2,&ft3,&ft4))
{
cout<<"success01!"<<endl;
cout<<pi.dwProcessId<<endl;
cout<<pi.dwThreadId<<endl;
cout<<pi.hProcess<<endl;
cout<<pi.hThread<<endl;
if(FileTimeToSystemTime(&ft3,&st1))
{
cout<<"success02!"<<endl;
// 把進(jìn)程以用戶模式已經(jīng)執(zhí)行的時(shí)間轉(zhuǎn)換為文件時(shí)間
if (FileTimeToSystemTime(&ft4,&st2))
{
n1 = st1.wHour + st2.wHour;
n2 = st1.wMinute + st2.wMinute;
n3 = st1.wSecond + st2.wSecond;
// 保存進(jìn)程所使用的CPU時(shí)間(單位:秒)到m_uiCpuTime變量里
m_uiCpuTime = n1 * 3600 + n2 * 60 + n3;
cout<<m_uiCpuTime<<endl;
cout<<st1.wHour<<"\t"<<":"<<st1.wMinute<<"\t"<<":"<<st1.wMilliseconds<<endl;
cout<<st2.wHour<<"\t"<<":"<<st2.wMinute<<"\t"<<":"<<st2.wMilliseconds<<endl;
cout<<"success!03"<<endl;
}
}
}
}
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -