adjtime(3)
π adjtime(3) β correct the time to synchronize the system clock π
okay bestie, this one is from the Library Functions Manual (section 3, library calls, you know the vibe) and it's literally the chill version of clock-fixing. no abrupt jumps, no drama, just β¨gentleβ¨ nudging. let's get into it π¦
πΈ NAME πΈ
adjtime β correct the time to synchronize the system clock
π LIBRARY π
Standard C library (libc, -lc)
β¨ SYNOPSIS β¨
#include <sys/time.h>
int adjtime(const struct timeval *delta, struct timeval *olddelta);
π Feature Test Macro Requirements for glibc (see feature_test_macros(7)) π
adjtime():- Since glibc 2.19:
_DEFAULT_SOURCE - glibc 2.19 and earlier:
_BSD_SOURCE
- Since glibc 2.19:
π«Ά DESCRIPTION π«Ά
so adjtime() gradually adjusts the system clock (the one you get back from gettimeofday(2)). like, it does not just yank the time, it eases it. the amount of time the clock needs to be adjusted by? that's specified in the structure that delta points to. and that structure is giving:
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
if the adjustment in delta is positive, the system clock gets sped up by some small percentage (basically adding a tiny bit of extra time to the clock value every second) until the adjustment finishes. if the adjustment in delta is negative, the clock gets slowed down the same way, just in reverse. no cap, it's symmetrical and it's iconic π«
okay now here's the tea β if there's already a clock adjustment from an earlier adjtime() call in progress, and then you make a later adjtime() call with delta not NULL, the earlier adjustment gets stopped. but β important β any part of that adjustment that already completed is not undone. periodt, it stays.
and if olddelta is not NULL, the buffer it points to gets used to return the amount of time remaining from any previous adjustment that hasn't finished yet. so you get the leftovers, basically π
π₯ RETURN VALUE π₯
- on success,
adjtime()returns0β¨ - on failure,
-1is returned, anderrnois set to indicate the error π
π ERRORS π
EINVALβ the adjustment indeltais outside the permitted range. (rude, but okay.)EPERMβ the caller does not have sufficient privilege to adjust the time. under Linux, theCAP_SYS_TIMEcapability is required. sorry bestie, you need the keys to the kingdom π
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7).
- Interface:
adjtime() - Attribute: Thread safety
- Value:
MT-Safe
(translation: she's thread-safe, she's stable, she's the moment π )
π STANDARDS π
None.
yes, literally just "None." β she's built different, she's not standardized, she's a free spirit π¦
β HISTORY β
4.3BSD, System V.
an icon of the old school, fr fr.
π§ NOTES π§
the adjustment that adjtime() makes to the clock is carried out in such a manner that the clock is always monotonically increasing. using adjtime() to adjust the time prevents the problems that could be caused for certain applications (e.g., make(1)) by abrupt positive or negative jumps in the system time. like, she never goes backwards, she never jumps scare-you-in-the-night style, she just glides π
adjtime() is intended to be used to make small adjustments to the system time. most systems impose a limit on the adjustment that can be specified in delta. in the glibc implementation, delta must be less than or equal to (INT_MAX / 1000000 - 2) and greater than or equal to (INT_MIN / 1000000 + 2) (respectively 2145 and -2145 seconds on i386). so yeah, tiny nudges only, no giant leaps π
π BUGS π
a longstanding bug meant that if delta was specified as NULL, no valid information about the outstanding clock adjustment was returned in olddelta. (in this circumstance, adjtime() should return the outstanding clock adjustment, without changing it.) this bug is fixed on systems with glibc 2.8 or later and Linux kernel 2.6.26 or later β
πΈ SEE ALSO πΈ
and that's the whole page, bestie!! πβ¨ go forth and gently nudge those clocks, stay monotonic, and remember: small adjustments only, always ask for CAP_SYS_TIME first π«Ά
mwah π this was Linux man-pages 6.20, dated 2026-02-08, signing off ππ¦
π¦ 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 2006, 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