Use the POSIX clock_gettime() function with CLOCK_MONOTONIC. See the man page for details.
clock_gettime()
CLOCK_MONOTONIC
There is clock_gettime:
struct timespec tp;clock_gettime(CLOCK_MONOTONIC, &tp);