Run time in seconds or milliseconds on Unix systems

I need a method that can give me the number of milliseconds or seconds elapsed since the system started. I could parse /proc/uptime , but I can't afford to lose performance on this I / 0 and parsing.

I use Linux and C / C ++. Maybe I can put Qt / Boost, but it's better to be something native.

+1
source share
2 answers

Why can't you afford to read /proc/uptime ? This is not a real file, so reading should be fast (there is no real I / O involved since the /proc/ file system contains pseudo files). Did you rate his reading?

You can also call clock_gettime with CLOCK_MONOTONIC

NB. This applies to Linux.

+12
source

You can try sysinfo.h .

+4
source

Source: https://habr.com/ru/post/986716/


All Articles