epoll_create1() — Linux system interface
Create an epoll instance with an initially empty interest list. Use EPOLL_CLOEXEC to avoid unintended inheritance. Unlike epoll_create, there is no size hint. The instance is itself an owned descriptor; close it when finished. Register descriptors with epoll_ctl and retrieve events with epoll_wait. Unsupported flag bits cause EINVAL; descriptor exhaustion can cause EMFILE. Compile the complete C example in a fresh private working directory using gcc -std=c17 -Wall -Wextra -Wpedantic -Werror example.c -o example; run ./example. Linux-specific interface or flags; tested on Linux/glibc only. These are libc-facing signatures, not raw architecture-specific syscall ABIs.
Formal Syntax & Structure
#include <sys/epoll.h>int epoll_create1(int flags);Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| flags | int | 0 or EPOLL_CLOEXEC. |
Return Value
Nonnegative owned descriptor on success. On failure, returns -1 and sets errno.
Working Example
#define _GNU_SOURCE#define _POSIX_C_SOURCE 200809L#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/epoll.h>#include <fcntl.h>
/* A failed check ends this short-lived demonstration. */#define CHECK(x) do { if (!(x)) { \ fprintf(stderr, "check failed at line %d: %s\n", __LINE__, #x); \ return EXIT_FAILURE; \} } while (0)
int main(void){ int e = epoll_create1(EPOLL_CLOEXEC); CHECK(e >= 0); int flags = fcntl(e, F_GETFD); CHECK(flags >= 0 && (flags & FD_CLOEXEC)); struct epoll_event event; CHECK(epoll_wait(e, &event, 1, 0) == 0); CHECK(close(e) == 0); puts("empty epoll instance; CLOEXEC set"); return EXIT_SUCCESS;}