Programmatically compute the start time of a process on Windows

后端 未结 2 448
死守一世寂寞
死守一世寂寞 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:51

    If I understand you right you want to know what time your process started, correct? So you'll want to look into GetProcessTimes

    If the process you're interested in is the current process, you can use GetCurrentProcess() to get the process handle that you'll need to call GetProcessTimes() this returns a pseudo-handle that you don't need to close.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题