NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |NOTES |HISTORY |SEE ALSO |NOTES |COLOPHON | |
SD_EVENT_RUN(3) sd_event_runSD_EVENT_RUN(3)sd_event_run, sd_event_loop - Run an event loop
#include <systemd/sd-event.h>int sd_event_run(sd_event *event, uint64_tusec);int sd_event_loop(sd_event *event);
sd_event_run()may be used to run a single iteration of the event loop specified in theevent parameter. The function waits until an event to process is available, and dispatches the registered handler for it. Theusec parameter specifies the maximum time (in microseconds) to wait for an event. Use(uint64_t) -1to specify an infinite timeout.sd_event_loop()invokessd_event_run()in a loop, thus implementing the actual event loop. The call returns as soon as exiting was requested usingsd_event_exit(3). The event loop objectevent is created withsd_event_new(3). Events sources to wait for and their handlers may be registered withsd_event_add_io(3),sd_event_add_time(3),sd_event_add_signal(3),sd_event_add_child(3),sd_event_add_defer(3),sd_event_add_post(3) andsd_event_add_exit(3). For low-level control of event loop execution, usesd_event_prepare(3),sd_event_wait(3) andsd_event_dispatch(3) which are wrapped bysd_event_run(). Along withsd_event_get_fd(3), these functions allow integration of ansd-event(3) event loop into foreign event loop implementations.
On failure, these functions return a negative errno-style error code.sd_event_run()returns a positive, non-zero integer if an event source was dispatched, and zero when the specified timeout hit before an event source has seen any event, and hence no event source was dispatched.sd_event_loop()returns the exit code specified when invokingsd_event_exit().Errors Returned errors may indicate the following problems:-EINVAL Theevent parameter is invalid orNULL.-EBUSY The event loop object is not in the right state (seesd_event_prepare(3) for an explanation of possible states).-ESTALE The event loop is already terminated.-ECHILD The event loop has been created in a different process, library or module instance. Other errors are possible, too.
Functions described here are available as a shared library, which can be compiled against and linked to with thelibsystemd pkg-config(1) file. The code described here usesgetenv(3), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not callsetenv(3) from a parallel thread. It is recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started.
sd_event_run()andsd_event_loop()were added in version 220.
systemd(1),sd-event(3),sd_event_new(3),sd_event_add_io(3),sd_event_add_time(3),sd_event_add_signal(3),sd_event_add_child(3),sd_event_add_inotify(3),sd_event_add_defer(3),sd_event_exit(3),sd_event_get_fd(3),sd_event_wait(3),GLib Main Event Loop[1]
1. GLib Main Event Loophttps://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html
This page is part of thesystemd (systemd system and service manager) project. Information about the project can be found at ⟨http://www.freedesktop.org/wiki/Software/systemd⟩. If you have a bug report for this manual page, see ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩. This page was obtained from the project's upstream Git repository ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11. (At that time, the date of the most recent commit that was found in the repository was 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 isnot part of the original manual page), send a mail to man-pages@man7.orgsystemd 258~rc2SD_EVENT_RUN(3)Pages that refer to this page:sd-event(3), sd_event_exit(3), sd_event_new(3), sd_event_wait(3), systemd.directives(7), systemd.index(7)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |