我正在寻找等同于 GetTickCount()
的内容在 Linux 上。
目前我正在使用 Python 的 time.time()
这大概会调用 gettimeofday()
.我担心的是返回的时间(unix 纪元),如果时钟被扰乱,例如被 NTP 扰乱,可能会不规律地改变。一个简单的进程或系统挂起时间,仅以恒定速率正向增加就足够了。
C 或 Python 中是否存在这样的时间函数?
最佳答案
您可以使用 CLOCK_MONOTONIC例如在 C:
struct timespec ts;
if(clock_gettime(CLOCK_MONOTONIC,&ts) != 0) {
//error
}
以 Python 方式查看此问题 - How do I get monotonic time durations in python?
关于python - 相当于 Linux 上的 GetTickCount(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3327163/