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 a timeval structure, 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 by ntp_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 constant NTP_PHASE_MAX, whose value is 16,000. no cap... except literally there is a cap and it's 16,000 πŸ’€
  • esterror β€” the estimated error, also in microseconds. you can set this one via ntp_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 an ntptimeval structure where the time, maxerror, and esterror fields are filled in.
  • ntp_gettimex() does the exact same task as ntp_gettime(), but it also returns information in the tai field. 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms