---
name: "sd-event"
section: "3"
platform: "linux"
package: "systemd-libs"
version: "262.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sd-event"
---

# sd-event(3)

A generic event loop implementation

## NAME

sd-event - A generic event loop implementation

## SYNOPSIS

```
#include <systemd/sd-event.h>
```

**pkg-config --cflags --libs libsystemd**

## DESCRIPTION

sd-event.h is part of [**libsystemd**(3)](/libsystemd/3.md) and provides a generic event loop implementation, based on Linux [**epoll**(7)](/epoll/7.md).

See [**sd\_event\_new**(3)](/sd_event_new/3.md), [**sd\_event\_run**(3)](/sd_event_run/3.md), [**sd\_event\_add\_io**(3)](/sd_event_add_io/3.md), [**sd\_event\_add\_time**(3)](/sd_event_add_time/3.md), [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md), [**sd\_event\_add\_child**(3)](/sd_event_add_child/3.md), [**sd\_event\_add\_inotify**(3)](/sd_event_add_inotify/3.md), [**sd\_event\_add\_defer**(3)](/sd_event_add_defer/3.md), [**sd\_event\_add\_memory\_pressure**(3)](/sd_event_add_memory_pressure/3.md), [**sd\_event\_source\_unref**(3)](/sd_event_source_unref/3.md), [**sd\_event\_source\_set\_priority**(3)](/sd_event_source_set_priority/3.md), [**sd\_event\_source\_set\_enabled**(3)](/sd_event_source_set_enabled/3.md), [**sd\_event\_source\_set\_userdata**(3)](/sd_event_source_set_userdata/3.md), [**sd\_event\_source\_get\_event**(3)](/sd_event_source_get_event/3.md), [**sd\_event\_source\_get\_pending**(3)](/sd_event_source_get_pending/3.md), [**sd\_event\_source\_set\_description**(3)](/sd_event_source_set_description/3.md), [**sd\_event\_source\_set\_prepare**(3)](/sd_event_source_set_prepare/3.md), [**sd\_event\_source\_set\_ratelimit**(3)](/sd_event_source_set_ratelimit/3.md), [**sd\_event\_wait**(3)](/sd_event_wait/3.md), [**sd\_event\_get\_fd**(3)](/sd_event_get_fd/3.md), [**sd\_event\_set\_watchdog**(3)](/sd_event_set_watchdog/3.md), [**sd\_event\_exit**(3)](/sd_event_exit/3.md), [**sd\_event\_now**(3)](/sd_event_now/3.md) for more information about the functions available.

The event loop design is targeted on running a separate instance of the event loop in each thread; it has no concept of distributing events from a single event loop instance onto multiple worker threads. Dispatching events is strictly ordered and subject to configurable priorities. In each event loop iteration a single event source is dispatched. Each time an event source is dispatched the kernel is polled for new events, before the next event source is dispatched. The event loop is designed to honor priorities and provide fairness within each priority. It is not designed to provide optimal throughput, as this contradicts these goals due the limitations of the underlying [**epoll**(7)](/epoll/7.md) primitives.

The event loop implementation provides the following features:

 1\. I/O event sources, based on [**epoll**(7)](/epoll/7.md)'s file descriptor watching, including edge triggered events (**EPOLLET**). See [**sd\_event\_add\_io**(3)](/sd_event_add_io/3.md).

 2\. Timer event sources, based on [**timerfd\_create**(2)](/timerfd_create/2.md), supporting the **CLOCK\_MONOTONIC**, **CLOCK\_REALTIME**, **CLOCK\_BOOTTIME** clocks, as well as the **CLOCK\_REALTIME\_ALARM** and **CLOCK\_BOOTTIME\_ALARM** clocks that can resume the system from suspend. When creating timer events a required accuracy parameter may be specified which allows coalescing of timer events to minimize power consumption. See [**sd\_event\_add\_time**(3)](/sd_event_add_time/3.md).

 3\. UNIX process signal events, based on [**signalfd**(2)](/signalfd/2.md), including full support for real-time signals, and queued parameters. See [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md).

 4\. Child process state change events, based on [**waitid**(2)](/waitid/2.md). See [**sd\_event\_add\_child**(3)](/sd_event_add_child/3.md).

 5\. Static event sources, of three types: defer, post and exit, for invoking calls in each event loop, after other event sources or at event loop termination. See [**sd\_event\_add\_defer**(3)](/sd_event_add_defer/3.md).

 6\. Event sources may be assigned a 64-bit priority value, that controls the order in which event sources are dispatched if multiple are pending simultaneously. See [**sd\_event\_source\_set\_priority**(3)](/sd_event_source_set_priority/3.md).

 7\. The event loop may automatically send watchdog notification messages to the service manager. See [**sd\_event\_set\_watchdog**(3)](/sd_event_set_watchdog/3.md).

 8\. The event loop may be integrated into foreign event loops, such as the GLib one. See [**sd\_event\_get\_fd**(3)](/sd_event_get_fd/3.md) for an example.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) from a parallel thread. It is recommended to only do calls to **setenv()** from an early phase of the program when no other threads have been started.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd\_event\_new**(3)](/sd_event_new/3.md), [**sd\_event\_run**(3)](/sd_event_run/3.md), [**sd\_event\_add\_io**(3)](/sd_event_add_io/3.md), [**sd\_event\_add\_time**(3)](/sd_event_add_time/3.md), [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md), [**sd\_event\_add\_child**(3)](/sd_event_add_child/3.md), [**sd\_event\_add\_inotify**(3)](/sd_event_add_inotify/3.md), [**sd\_event\_add\_defer**(3)](/sd_event_add_defer/3.md), [**sd\_event\_add\_memory\_pressure**(3)](/sd_event_add_memory_pressure/3.md), [**sd\_event\_source\_unref**(3)](/sd_event_source_unref/3.md), [**sd\_event\_source\_set\_priority**(3)](/sd_event_source_set_priority/3.md), [**sd\_event\_source\_set\_enabled**(3)](/sd_event_source_set_enabled/3.md), [**sd\_event\_source\_set\_userdata**(3)](/sd_event_source_set_userdata/3.md), [**sd\_event\_source\_get\_event**(3)](/sd_event_source_get_event/3.md), [**sd\_event\_source\_get\_pending**(3)](/sd_event_source_get_pending/3.md), [**sd\_event\_source\_set\_description**(3)](/sd_event_source_set_description/3.md), [**sd\_event\_source\_set\_prepare**(3)](/sd_event_source_set_prepare/3.md), [**sd\_event\_source\_set\_ratelimit**(3)](/sd_event_source_set_ratelimit/3.md), [**sd\_event\_wait**(3)](/sd_event_wait/3.md), [**sd\_event\_get\_fd**(3)](/sd_event_get_fd/3.md), [**sd\_event\_set\_watchdog**(3)](/sd_event_set_watchdog/3.md), [**sd\_event\_exit**(3)](/sd_event_exit/3.md), [**sd\_event\_now**(3)](/sd_event_now/3.md), [**epoll**(7)](/epoll/7.md), [**timerfd\_create**(2)](/timerfd_create/2.md), [**signalfd**(2)](/signalfd/2.md), [**waitid**(2)](/waitid/2.md)
