Programmatically compute the start time of a process on Windows

后端 未结 2 454
死守一世寂寞
死守一世寂寞 2021-01-06 20:26

I\'m writing c/c++ code on Windows using Visual Studio. I want to know how to calculate the start time of my process effectively. Can I just use gettimeofday()? I\'ve fou

2条回答
  •  逝去的感伤
    2021-01-06 20:54

    My question is closed. I'm find example to GetProcessTime from process shapshot and some guys give link with this question.

    I'm released this and that is my example:

    HANDLE hSnapshot; //variable for save snapshot of process
    PROCESSENTRY32 Entry; //variable for processing with snapshot
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //do snapshot
    Entry.dwSize = sizeof(Entry);    //assign size of Entry variables
    Process32First(hSnapshot, &Entry); //assign Entry variable to start of snapshot
    HANDLE hProc; //this variable for handle process
    SYSTEMTIME sProcessTime; // this variable for get system (usefull) time
    FILETIME fProcessTime, ftExit, ftKernel, ftUser; // this variables for get process start time and etc.
    do 
    {
        hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, Entry.th32ProcessID);//Open process for all access
        GetProcessTimes(hProc, &fProcessTime, &ftExit, &ftKernel, &ftUser);//Get process time
        FileTimeToSystemTime(&fProcessTime, &sProcessTime); //and now, start time of process at sProcessTime variable at usefull format.
    } while (Process32Next(hSnapshot, &Entry)); //while not end of list(snapshot)
    

提交回复
热议问题