NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: nonexistent clocks



Hi Jan,
According to tests/lib/libc/sys/t_clock_gettime.c
""These clocks aren't supported but are documented"
	    " in clock_gettime(2) for some reason"

There's also a PR in about CLOCK_MONOTONIC & what it actually represents:
https://gnats.netbsd.org/60315

Cheers


On 24/06/2026 9:56 pm, Jan Stary wrote:
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;
}




Home | Main Index | Thread Index | Old Index