Get uptime in seconds or miliseconds on Unix like systems

前端 未结 2 1981
别那么骄傲
别那么骄傲 2021-01-26 20:18

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 lo

相关标签:
2条回答
  • 2021-01-26 20:51

    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?

    You might also call clock_gettime with CLOCK_MONOTONIC

    NB. This is specific to Linux.

    0 讨论(0)
  • 2021-01-26 21:00

    You could try sysinfo.h.

    0 讨论(0)
提交回复
热议问题