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

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

问题描述

我正在寻找等效于 GetTickCount() 在 Linux 上.

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

目前我正在使用 Python 的 time.time() 大概调用了 <代码>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:

You can use CLOCK_MONOTONIC e.g. in C:

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

以 Python 方式查看此问题 - How do I在 python 中获取单调持续时间?

See this question for a Python way - How do I get monotonic time durations in python?

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

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