Dear all,
the code below works for CLOCK_REALTIME and CLOCK_MONOTONIC,
but not for CLOCK_VIRTUAL or CLOCK_PROF. Why is that?
All of those are documented in clock_gettime(2) and
I don't see anything about some of them being special
or only available in some special contexts.
Running the code ends in
clock: Invalid argument
which I suppose is the first EINVAL in ERRORS
(I am not _setting_ the clock):
The clock_id argument does not specify a known clock.
Why are they "not known"?
Jan
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <err.h>
void
show(clockid_t id, char* name)
{
struct timespec ts;
struct timespec cr;
if (clock_gettime(id, &ts) == -1)
err(1, NULL);
if (clock_getres(id, &cr) == -1)
err(1, NULL);
printf("%s %10lld.%09ld s, res %5ld ns\n",
name, ts.tv_sec, ts.tv_nsec, cr.tv_nsec);
}
int
main(void)
{
show(CLOCK_REALTIME, "real time");
show(CLOCK_MONOTONIC, "monotonic");
show(CLOCK_VIRTUAL, "virtual ");
show(CLOCK_PROF, "prof ");
return 0;
}