Is CLOCK_MONOTONIC a process (or thread) specific?

If I get the time using clock_gettime (CLOCK_MONOTONIC, x), then the income is called (for example, sched_yield ()), and then get the time CLOCK_MONOTONIC again, will the time difference include the time during which the program was not executed (received), or does CLOCK_MONOTONIC only track program execution time? My tests seem to imply the latter, but I would like to know for sure.

Also, if CLOCK_MONOTONIC does not include the specified time, is there another monotonous timer (i.e. one is not prone to jumps caused by ntp)?

+6
c multithreading linux time process
source share
2 answers

Answer Maxim and comments on this answered the second part of your question, I suppose. To extend the answer to the first part, POSIX 2008 announces

If the Monotonic Clock option is supported, all implementations shall support a clock_id of CLOCK_MONOTONIC defined in <time.h>. This clock represents the monotonic clock for the system. For this clock, the value returned by clock_gettime() represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the Epoch). This point does not change after system start-up time.

In particular, pay attention to the "monotonous clock for the system." That is, for each system, and not for the process, it continues to tick, even if your process is not running. In addition, β€œThis point does not change after the system starts up time,” which again means that it continues to tick regardless of whether a particular process is running or sleeping.

So, either you found an error in the Linux implementation, or most likely in your test program.

+8
source share

The only difference between CLOCK_REALTIME and CLOCK_MONOTONIC is that the latter cannot be set. This clock is ticking even if your process is not running.

http://www.opengroup.org/onlinepubs/009604599/functions/clock_getres.html

Please note that the absolute value of a monotonous clock is meaningless (since its origin is arbitrary), and therefore there is no need to establish it. In addition, real-time applications can rely on the fact that the value of this clock is never set, and therefore the time intervals measured with this clock will not be affected by the clock_settime () calls.

On Linux, it is surprising that CLOCK_MONOTONIC still suffers from NTP adjustments so that it can go back. Consequently, they added a few more hours of CLOCK_MONOTONIC_RAW:

man clock_gettime

CLOCK_MONOTONIC_RAW (since Linux 2.6.28; dependent on Linux) Like CLOCK_MONOTONIC, but provides access to raw hardware-based time that is not subject to NTP settings.

+4
source share

All Articles