在Windows上以编程方式计算进程的开始时间 [英] Programmatically compute the start time of a process on Windows

查看:69
本文介绍了在Windows上以编程方式计算进程的开始时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio在Windows上编写c/c ++代码.我想知道如何有效地计算过程的开始时间.我可以只使用gettimeofday()吗?我已经从Google找到以下代码,但我不知道它的实际作用:

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 found the following code from google but I don't understand what it's doing really :

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
  FILETIME ft;
  unsigned __int64 tmpres = 0;
  static int tzflag;

  if (NULL != tv)
  {
    GetSystemTimeAsFileTime(&ft);

    //I'm lost at this point
    tmpres |= ft.dwHighDateTime;
    tmpres <<= 32;
    tmpres |= ft.dwLowDateTime;

    /*converting file time to unix epoch*/
    tmpres /= 10;  /*convert into microseconds*/
    tmpres -= DELTA_EPOCH_IN_MICROSECS; 
    tv->tv_sec = (long)(tmpres / 1000000UL);
    tv->tv_usec = (long)(tmpres % 1000000UL);
  }

  if (NULL != tz)
  {
    if (!tzflag)
    {
      _tzset();
      tzflag++;
    }
    tz->tz_minuteswest = _timezone / 60;
    tz->tz_dsttime = _daylight;
  }

  return 0;
}

推荐答案

如果我理解正确,那么您想知道流程什么时候开始,对吗?因此,您需要研究 GetProcessTimes

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

如果您感兴趣的进程是当前进程,则可以使用 GetCurrentProcess()来获取需要调用 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.

这篇关于在Windows上以编程方式计算进程的开始时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆