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

# timer\_settime(2)

arm/disarm and fetch state of POSIX per-process timer

## NAME

timer\_settime, timer\_gettime - arm/disarm and fetch state of POSIX per-process timer

## LIBRARY

Real-time library (*librt*, *-lrt*)

## SYNOPSIS

```
#include <time.h>
```

**int timer\_gettime(timer\_t** *timerid***, struct itimerspec \****curr\_value***);** **int timer\_settime(timer\_t** *timerid***, int** *flags***,**                   **const struct itimerspec \*restrict** *new\_value***,**                   **struct itimerspec \*\_Nullable restrict** *old\_value***);**

Feature Test Macro Requirements for glibc (see [**feature\_test\_macros**(7)](/feature_test_macros/7.md)):

**timer\_settime**(), **timer\_gettime**():

```
    _POSIX_C_SOURCE >= 199309L
```

## DESCRIPTION

**timer\_settime**() arms or disarms the timer identified by *timerid*. The *new\_value* argument is pointer to an *itimerspec* structure that specifies the new initial value and the new interval for the timer. The *itimerspec* structure is described in [**itimerspec**(3type)](/itimerspec/3type.md).

Each of the substructures of the *itimerspec* structure is a [**timespec**(3)](/timespec/3.md) structure that allows a time value to be specified in seconds and nanoseconds. These time values are measured according to the clock that was specified when the timer was created by [**timer\_create**(2)](/timer_create/2.md).

If *new\_value-\>it\_value* specifies a nonzero value (i.e., either subfield is nonzero), then **timer\_settime**() arms (starts) the timer, setting it to initially expire at the given time. (If the timer was already armed, then the previous settings are overwritten.) If *new\_value-\>it\_value* specifies a zero value (i.e., both subfields are zero), then the timer is disarmed.

The *new\_value-\>it\_interval* field specifies the period of the timer, in seconds and nanoseconds. If this field is nonzero, then each time that an armed timer expires, the timer is reloaded from the value specified in *new\_value-\>it\_interval*. If *new\_value-\>it\_interval* specifies a zero value, then the timer expires just once, at the time specified by *it\_value*.

By default, the initial expiration time specified in *new\_value-\>it\_value* is interpreted relative to the current time on the timer's clock at the time of the call. This can be modified by specifying **TIMER\_ABSTIME** in *flags*, in which case *new\_value-\>it\_value* is interpreted as an absolute value as measured on the timer's clock; that is, the timer will expire when the clock value reaches the value specified by *new\_value-\>it\_value*. If the specified absolute time has already passed, then the timer expires immediately, and the overrun count (see [**timer\_getoverrun**(2)](/timer_getoverrun/2.md)) will be set correctly.

If the value of the **CLOCK\_REALTIME** clock is adjusted while an absolute timer based on that clock is armed, then the expiration of the timer will be appropriately adjusted. Adjustments to the **CLOCK\_REALTIME** clock have no effect on relative timers based on that clock.

If *old\_value* is not NULL, then it points to a buffer that is used to return the previous interval of the timer (in *old\_value-\>it\_interval*) and the amount of time until the timer would previously have next expired (in *old\_value-\>it\_value*).

**timer\_gettime**() returns the time until next expiration, and the interval, for the timer specified by *timerid*, in the buffer pointed to by *curr\_value*. The time remaining until the next timer expiration is returned in *curr\_value-\>it\_value*; this is always a relative value, regardless of whether the **TIMER\_ABSTIME** flag was used when arming the timer. If the value returned in *curr\_value-\>it\_value* is zero, then the timer is currently disarmed. The timer interval is returned in *curr\_value-\>it\_interval*. If the value returned in *curr\_value-\>it\_interval* is zero, then this is a "one-shot" timer.

## RETURN VALUE

On success, **timer\_settime**() and **timer\_gettime**() return 0. On error, -1 is returned, and *errno* is set to indicate the error.

## ERRORS

These functions may fail with the following errors:

- **EFAULT**

  *new\_value*, *old\_value*, or *curr\_value* is not a valid pointer.

- **EINVAL**

  *timerid* is invalid.

**timer\_settime**() may fail with the following errors:

- **EINVAL**

  *new\_value.it\_value* is negative; or *new\_value.it\_value.tv\_nsec* is negative or greater than 999,999,999.

## STANDARDS

POSIX.1-2024.

## HISTORY

Linux 2.6. POSIX.1-2001.

## EXAMPLES

See [**timer\_create**(2)](/timer_create/2.md).

## SEE ALSO

[**timer\_create**(2)](/timer_create/2.md), [**timer\_getoverrun**(2)](/timer_getoverrun/2.md), [**timespec**(3)](/timespec/3.md), [**time**(7)](/time/7.md)
