---
name: "timer_create"
section: "2freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/timer_create/2freebsd"
---

# timer\_create(2freebsd)

create a per-process timer (REALTIME)

## NAME

**timer\_create** – create a per-process timer (REALTIME)

## LIBRARY

library “librt”

## SYNOPSIS

**#include \<time.h\>**

**#include \<signal.h\>**

*int*\

**timer\_create**(*clockid\_t clockid*, *struct sigevent \*restrict evp*, *timer\_t \*restrict timerid*);

## DESCRIPTION

The **timer\_create**() system call creates a per-process timer using the specified clock, *clock\_id*, as the timing base. The **timer\_create**() system call returns, in the location referenced by *timerid*, a timer ID of type *timer\_t* used to identify the timer in timer requests. This timer ID is unique within the calling process until the timer is deleted. The particular clock, *clock\_id*, is defined in ⟨time.h⟩. The timer whose ID is returned is in a disarmed state upon return from **timer\_create**().

The *evp* argument, if non-NULL, points to a *sigevent* structure. This structure, allocated by the application, defines the asynchronous notification to occur when the timer expires.

If *evp-\>sigev\_notify* is SIGEV\_SIGNO or SIGEV\_THREAD\_ID, the signal specified in *evp-\>sigev\_signo* will be sent to the calling process (SIGEV\_SIGNO) or to the thread whose LWP ID is *evp-\>sigev\_notify\_thread\_id* (SIGEV\_THREAD\_ID). The information for the queued signal will include:

| | |
| --- | --- |
| **Member** | **Value** |
| *si\_code* | SI\_TIMER |
| *si\_value* |  |
| *si\_timerid* | timer ID |
| *si\_overrun* | timer overrun count |
| *si\_errno* |  |

If the *evp* argument is NULL, the effect is as if the *evp* argument pointed to a *sigevent* structure with the *sigev\_notify* member having the value SIGEV\_SIGNAL, the *sigev\_signo* having a default signal number (SIGALRM), and the *sigev\_value* member having the value of the timer ID.

This implementation supports a *clock\_id* of CLOCK\_REALTIME or CLOCK\_MONOTONIC.

If *evp-\>sigev\_notify* is SIGEV\_THREAD and *sev-\>sigev\_notify\_attributes* is not NULL, if the attribute pointed to by *sev-\>sigev\_notify\_attributes* has a thread stack address specified by a call to **pthread\_attr\_setstack**() or **pthread\_attr\_setstackaddr**(), the results are unspecified if the signal is generated more than once.

## RETURN VALUES

If the call succeeds, **timer\_create**() returns zero and updates the location referenced by *timerid* to a *timer\_t*, which can be passed to the per-process timer calls. If an error occurs, the system call returns a value of -1 and the global variable *errno* is set to indicate the error. The value of *timerid* is undefined if an error occurs.

## ERRORS

The **timer\_create**() system call will fail if:

- \[EAGAIN\]

  The calling process has already created all of the timers it is allowed by this implementation.

- \[EINVAL\]

  The specified clock ID is not supported.

- \[EINVAL\]

  The specified asynchronous notification method is not supported.

- \[EFAULT\]

  Any arguments point outside the allocated address space or there is a memory protection fault.

## SEE ALSO

[clock\_getres(2)](/clock_getres/2.md), [timer\_delete(2)](/timer_delete/2.md), [timer\_getoverrun(2)](/timer_getoverrun/2.md), [sigevent(3)](/sigevent/3.md), [siginfo(3)](/siginfo/3.md)

## STANDARDS

The **timer\_create**() system call conforms to IEEE Std 1003.1-2004 (“POSIX.1”).

## HISTORY

Support for POSIX per-process timer first appeared in FreeBSD 7.0.
