我需要一个方法,它可以给我从系统启动以来经过的毫秒数或秒数。 我可以解析 / proc / uptime ,但我不能失去在这个I / 0和解析的性能。
I need a method which can give me the number of miliseconds or seconds, elapsed since the system was started. I could parse /proc/uptime , but i can't afford to lose performance over this I/0 and parsing.
我使用Linux和C / C ++。
I'm using Linux and C/C++. Maybe i can put some Qt/Boost, but is better to be something native.
推荐答案为什么你不能读懂 / proc / uptime ?它不是真正的文件,所以读取它应该是快速的(没有真正的i / o涉及,因为 / proc / 文件系统包含伪文件)。
Why cannot you afford reading /proc/uptime? It is not a real file so reading it should be quick (there is no real i/o involved, since the /proc/ filesystem contains pseudo-files). Did you benchmark its reading?
您也可以拨打 clock_gettime a>与 CLOCK_MONOTONIC
You might also call clock_gettime with CLOCK_MONOTONIC
NB。这是特定于Linux的。
NB. This is specific to Linux.
更多推荐
在类Unix系统上以秒或毫秒为单位获取正常运行时间
发布评论