相当于在Linux上的GetTickCount() [英] Equivalent to GetTickCount() on Linux

查看:1530
本文介绍了相当于在Linux上的GetTickCount()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个相当于<一个href=\"http://msdn.microsoft.com/en-us/library/ms724408%28VS.85%29.aspx\"><$c$c>GetTickCount()在Linux上。

I'm looking for an equivalent to GetTickCount() on Linux.

presently我使用Python的 选定了time.time() 其中presumably调用,直至<一个href=\"http://www.kernel.org/doc/man-pages/online/pages/man2/gettimeofday.2.html\"><$c$c>gettimeofday().我担心的是时间返回(Unix纪元),可能会不稳定改变,如果时钟混乱搭配,如NTP。一个简单的过程或系统壁时,即只在一个恒定的速率就足够了积极增加

Presently I am using Python's time.time() which presumably calls through to gettimeofday(). My concern is that the time returned (the unix epoch), may change erratically if the clock is messed with, such as by NTP. A simple process or system wall time, that only increases positively at a constant rate would suffice.

请问用C或Python上述任何时间函数存在吗?

Does any such time function in C or Python exist?

推荐答案

您可以使用 CLOCK_MONOTONIC 如:在C:

struct timespec ts;
if(clock_gettime(CLOCK_MONOTONIC,&ts) != 0) {
 //error
}

请参阅这个问题的Python的方式 - <一个href=\"http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python\">http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python

See this question for a Python way - http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python

这篇关于相当于在Linux上的GetTickCount()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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