timespec_get(3)
π timespec_get(3) π
okay bestie, welcome to the timespec_get page from the Library Functions Manual β yes this is a section 3 manual page and yes it's about the ISO C interface to clock and time functions. grab a boba, we're doing time today πβ¨
πΈ NAME πΈ
timespec_get, timespec_getres β the ISO C interface to clock and time functions. iykyk, this is the glow-up of getting the time but make it standardised π
π LIBRARY π
Standard C library, aka libc, aka link it with -lc. she's everywhere, she's iconic, she's already in your binary π
β¨ SYNOPSIS β¨
#include <time.h>
int timespec_get(struct timespec *res, int base);
int timespec_getres(struct timespec *tp, int base);
π Feature Test Macro Requirements for glibc (see feature_test_macros(7)) π
okay so glibc is picky about which macros you define before you get to play with these, bestie, so listen up:
timespec_get(),TIME_UTCβ you gotta have_ISOC11_SOURCEπ«timespec_getres(),TIME_MONOTONIC,TIME_ACTIVE,TIME_THREAD_ACTIVEβ you gotta have_ISOC23_SOURCEπ«
π¦ DESCRIPTION π¦
so, timespec_get() stores the current time β based on the time base you picked β into the timespec(3type) structure that res points at. it literally hands you the time. no cap π«Ά
and timespec_getres()? she stores the resolution of times retrieved by timespec_get() with that specified time base into the timespec(3type) structure that tp points at β but only if tp is non-NULL. like, if tp is NULL she justβ¦ doesn't. π also, for any particular time base, that resolution is constant for the lifetime of the calling process. it does not change on you. periodt.
The time base base is one of these iconic options:
TIME_UTCβ a system-wide time base measuring real time, aka wall-clock time. the time and resolution in this base are exactly the same as what you'd get fromclock_gettime(CLOCK_REALTIME, res)andclock_getres(CLOCK_REALTIME, tp). same energy, different font πTIME_MONOTONICβ a time base that measures time since some unspecified point in the past, and the time within a process will never decrease, even if the system's real time clock gets set or adjusted. she only goes forward, main character energy. the time and resolution here are the same asclock_gettime(CLOCK_MONOTONIC, res)andclock_getres(CLOCK_MONOTONIC, tp)β¨TIME_ACTIVEβ a process-specific time base measuring CPU time consumed by the calling process. the time and resolution are the same asclock_gettime(CLOCK_PROCESS_CPUTIME_ID, res)andclock_getres(CLOCK_PROCESS_CPUTIME_ID, tp)π₯TIME_THREAD_ACTIVEβ a thread-specific time base measuring CPU time consumed by the calling thread. the time and resolution matchclock_gettime(CLOCK_THREAD_CPUTIME_ID, res)andclock_getres(CLOCK_THREAD_CPUTIME_ID, tp)π
π«Ά RETURN VALUE π«Ά
timespec_get()returns the nonzerobaseif it's a supported time base and the current time was successfully retrieved. otherwise it returns0. that's it, that's the vibe check πtimespec_getres()returns the nonzerobaseif it's a supported time base, or0otherwise.
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
- Interface:
timespec_get(),timespec_getres() - Attribute: Thread safety
- Value:
MT-Safe
(that means she's safe to share with all your threads. no drama, no races, we love to see it π)
π STANDARDS π
timespec_get()β C23, POSIX.1-2024.TIME_UTCβ C23 (though ISO C doesn't specify the time epoch, so don't come for her), POSIX.1-2024.timespec_getres()β C23.TIME_MONOTONICβ C23.TIME_ACTIVEβ C23.TIME_THREAD_ACTIVEβ C23.
π HISTORY π
timespec_get()β C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.TIME_UTCβ C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.timespec_getres()β C23, glibc 2.34.TIME_MONOTONICβ C23, glibc 2.43.TIME_ACTIVEβ C23, glibc 2.43.TIME_THREAD_ACTIVEβ C23, glibc 2.43.
(the girls that came in 2.43 are the new kids and they're already slaying π§)
π SEE ALSO π
and that's the whole page bestie, go forth and timestamp responsibly πβ¨
Linux man-pages 6.20 Β· 2026-02-11 β mwah, kiss kiss, this page was brought to you by that exact version and date, no cap ππ
π¦ 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: 0BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms