ntp_gettime(3)
π ntp_gettime(3) β Library Functions Manual π
okay bestie, so this is the ntp_gettime page from the Library Functions Manual, and it's genuinely so cute β two little functions that let you peek at what the system clock is doing. clock gossip. let's get into it πβ¨
πΈ NAME πΈ
ntp_gettime, ntp_gettimex β get time parameters (NTP daemon interface)
π LIBRARY π
Standard C library (libc, -lc)
like, the regular one. no weird extra libs needed, we're chillin π
β¨ SYNOPSIS β¨
#include <sys/timex.h>
int ntp_gettime(struct ntptimeval *ntv);
int ntp_gettimex(struct ntptimeval *ntv);
two functions, same signature, one of them just does a lil extra. slay.
π¦ DESCRIPTION π¦
okay so both of these APIs hand information back to you through the ntv argument, which is a pointer to a structure that looks exactly like this:
struct ntptimeval {
struct timeval time; /* Current time */
long maxerror; /* Maximum error */
long esterror; /* Estimated error */
long tai; /* TAI offset */
/* Further padding bytes allowing for future expansion */
};
not me being obsessed with a struct that has padding bytes in it for future β¨manifestationβ¨. anyway, here's what every single field is doing:
the fields, one by one π«Ά
timeβ the current time, expressed as atimevalstructure, which itself is giving:
struct timeval {
time_t tv_sec; /* Seconds since the Epoch */
suseconds_t tv_usec; /* Microseconds */
};
seconds plus microseconds. the classic. iconic.
maxerrorβ the max error, measured in microseconds. this one can be initialized byntp_adjtime(3), and then it gets bumped up periodically (on Linux that's every second, so, constantly, bestie) β BUT it's clamped to an upper limit. which limit? the kernel constantNTP_PHASE_MAX, whose value is16,000. no cap... except literally there is a cap and it's16,000πesterrorβ the estimated error, also in microseconds. you can set this one viantp_adjtime(3)so it holds an estimate of the difference between the system clock and the true time. plot twist tho β this value is not used inside the kernel. it's just... sitting there. aesthetic. decorative. a little guy.taiβ the TAI (Atomic International Time) offset.
now which function does what π
ntp_gettime()gives you back anntptimevalstructure where thetime,maxerror, andesterrorfields are filled in.ntp_gettimex()does the exact same task asntp_gettime(), but it also returns information in thetaifield. so she's the overachiever. main character energy fr fr.
π« RETURN VALUE π«
the return values for ntp_gettime() and ntp_gettimex() are as for adjtimex(2).
and here's the cute part: given a correct pointer argument, these functions always succeed. they just do not miss. π―
ngl the "given a correct pointer argument" is doing a lot of heavy lifting there. pass it a valid pointer and you're golden. pass it nonsense and that's on you, bestie. π
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7).
- Interface:
ntp_gettime(),ntp_gettimex() - Attribute: Thread safety
- Value:
MT-Safe
translation: MT-Safe means you can call these from multiple threads and it's fine. the girls are safe. π
β STANDARDS β
ntp_gettime()β NTP Kernel Application Program Interface.ntp_gettimex()β GNU.
one's the standard API, one's the GNU bonus track. both valid. π«Ά
π§ HISTORY π§
ntp_gettime()β glibc 2.1.ntp_gettimex()β glibc 2.12.
so ntp_gettimex() is the younger sibling that showed up in glibc 2.12. she's new-ish and she brought the TAI offset with her. πΈ
π SEE ALSO π
adjtimex(2), ntp_adjtime(3), time(7)
NTP "Kernel Application Program Interface"
go read those next, bestie, they're the whole friend group π
mwah, that's the whole page. every flag, field, value, function, macro and reference, all of it, no crumbs left behind. π
signing off with the receipts: this is from Linux man-pages 6.20, dated 2026-02-08, and the page is ntp_gettime(3). πβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms