TiIf a program requires measuring elapsed time, you will need an individual timer that will be independent even if the user changes the time on the system clock. In Linux there are several different implementations for different cases (https://linux.die.net/man/3/clock_gettime):

  • CLOCK_REALTIME
    System-wide realtime clock. Setting this clock requires appropriate privileges.
  • CLOCK_MONOTONIC
    Clock that cannot be set and represents monotonic time since some unspecified starting point.
  • CLOCK_PROCESS_CPUTIME_ID
    High-resolution per-process timer from the CPU.
  • CLOCK_THREAD_CPUTIME_ID
    Thread-specific CPU-time clock.

To safely measure the elapsed time, you need a clock that ticks out time continuously, without any jumps when a user sets the system time. This kind of clock is called a monotonic clock. (CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW which gives more accurate results over very short intervals)

 

Author

Write A Comment