If I get the time using clock_gettime(CLOCK_MONOTONIC,x), then call yield (e.g. sched_yield()), then get the CLOCK_MONOTONIC time again, will the difference in times include the time the program wasn’t running (having yielded), or does CLOCK_MONOTONIC only track the time during which the program is executing? My tests seem to imply the latter, but I’d like to know for sure.
Also, if CLOCK_MONOTONIC doesn’t include the time yielded, is there another monotonic timer (ie. one not subject to jumps caused by ntp) that does?
The answer Maxim and comments to that answered the second part of your question, I believe. To expand on the answer for the first part, POSIX 2008 states
In particular, note “the monotonic clock for the system”. That is, per-system and not per-process, it keeps ticking even though your process is not running. Also, “This point does not change after system start-up time.”, which again implies that it keeps ticking regardless of whether a particular process is running or sleeping.
So, either you have found a bug in the Linux implementation, or more likely, in your test program.