---
name: "timespec_get"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/timespec_get"
---

# timespec\_get(3)

ISO C interface to clock and time functions

## NAME

timespec\_get, timespec\_getres - ISO C interface to clock and time functions

## LIBRARY

Standard C library (*libc*, *-lc*)

## 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)](/feature_test_macros/7.md)):

**timespec\_get**(), **TIME\_UTC**:

```
    _ISOC11_SOURCE
```

**timespec\_getres**(), **TIME\_MONOTONIC**, **TIME\_ACTIVE**, **TIME\_THREAD\_ACTIVE**:

```
    _ISOC23_SOURCE
```

## DESCRIPTION

The **timespec\_get**() function stores the current time, based on the specified time base, in the [**timespec**(3type)](/timespec/3type.md) 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)](/timespec/3type.md) 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.

The time base *base* is one of the following:

- **TIME\_UTC**

  A system-wide time base that measures real (i.e., wall-clock) time. 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.

- **TIME\_MONOTONIC**

  A time base that measures time since an unspecified point in the past, where the time within a process will not decrease even if the system's real time clock is set or adjusted. The time and resolution in this time base are the same as those retrieved by *clock\_gettime(CLOCK\_MONOTONIC, res)* and *clock\_getres(CLOCK\_MONOTONIC, tp)*, respectively.

- **TIME\_ACTIVE**

  A process-specific time base that measures CPU time consumed by the calling process. The time and resolution in this time base are the same as those retrieved by *clock\_gettime(CLOCK\_PROCESS\_CPUTIME\_ID, res)* and *clock\_getres(CLOCK\_PROCESS\_CPUTIME\_ID, tp)*, respectively.

- **TIME\_THREAD\_ACTIVE**

  A thread-specific time base that measures CPU time consumed by the calling thread. The time and resolution in this time base are the same as those retrieved by *clock\_gettime(CLOCK\_THREAD\_CPUTIME\_ID, res)* and *clock\_getres(CLOCK\_THREAD\_CPUTIME\_ID, tp)*, respectively.

## RETURN VALUE

**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

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **timespec\_get**(), **timespec\_getres**() | Thread safety | MT-Safe |

## STANDARDS

- **timespec\_get**() **TIME\_UTC**

  C23, POSIX.1-2024.

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

- **timespec\_getres**() **TIME\_MONOTONIC** **TIME\_ACTIVE** **TIME\_THREAD\_ACTIVE**

  C23.

## HISTORY

- **timespec\_get**() **TIME\_UTC**

  C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.

- **timespec\_getres**()

  C23, glibc 2.34.

- **TIME\_MONOTONIC** **TIME\_ACTIVE** **TIME\_THREAD\_ACTIVE**

  C23, glibc 2.43.

## SEE ALSO

[**clock\_gettime**(2)](/clock_gettime/2.md), [**clock\_getres**(2)](/clock_getres/2.md)
