timespec_get(3) — Linux manual page

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | SEE ALSO | COLOPHON

timespec_get(3)          Library Functions Manual         timespec_get(3)

NAME         top

       timespec_get, timespec_getres - ISO C interface to clock and time
       functions

LIBRARY         top

       Standard C library (libc, -lc),

SYNOPSIS         top

       #include <time.h>

       int timespec_get(struct timespec *res, int base);
       int timespec_getres(struct timespec *tp, int base);

DESCRIPTION         top

       The timespec_get() function stores the current time, based on the
       specified time base, in the timespec(3type) structure pointed to
       by res.

       The timespec_getres() function stores the resolution of times
       retrieved by timespec_get() with the specified time base in the
       timespec(3type) structure pointed to by tp, if tp is non-NULL.
       For a particular time base, the resolution is constant for the
       lifetime of the calling process.

       TIME_UTC is always a supported time base, and is the only time
       base supported on Linux.  The time and resolution in this time
       base are the same as those retrieved by
       clock_gettime(CLOCK_REALTIME, res) and
       clock_getres(CLOCK_REALTIME, tp), respectively.  Other systems may
       support additional time bases.

RETURN VALUE         top

       timespec_get() returns the nonzero base if it is a supported time
       base and the current time was successfully retrieved, or 0
       otherwise.

       timespec_getres() returns the nonzero base if it is a supported
       time base, or 0 otherwise.

ATTRIBUTES         top

       For an explanation of the terms used in this section, see
       attributes(7).
       ┌──────────────────────────────────────┬───────────────┬─────────┐
       │ Interface                            Attribute     Value   │
       ├──────────────────────────────────────┼───────────────┼─────────┤
       │ timespec_get(), timespec_getres()    │ Thread safety │ MT-Safe │
       └──────────────────────────────────────┴───────────────┴─────────┘

STANDARDS         top

       timespec_get()
       TIME_UTC
              C23 (though ISO C doesn't specify the time epoch),
              POSIX.1-2024.

       timespec_getres()
              C23.

HISTORY         top

       timespec_get()
       TIME_UTC
              C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.

       timespec_getres()
              C23, glibc 2.34.

SEE ALSO         top

       clock_gettime(2), clock_getres(2)

COLOPHON         top

       This page is part of the man-pages (Linux kernel and C library
       user-space interface documentation) project.  Information about
       the project can be found at 
       ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report
       for this manual page, see
       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
       This page was obtained from the tarball man-pages-6.15.tar.gz
       fetched from
       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
       2025-08-11.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-
       to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not
       part of the original manual page), send a mail to
       [email protected]

Linux man-pages 6.15            2025-02-10                timespec_get(3)