Skip to content

epoll_create1()

Purpose

Creates an epoll instance and returns a file descriptor used by epoll_ctl() and epoll_wait().

#include <sys/epoll.h>

Prototype

int epoll_create1(int flags);

Parameters

  • flags: normally EPOLL_CLOEXEC or 0.

Return Value

  • Success: returns a new epoll file descriptor.
  • Failure: returns -1 and sets errno.

Minimal Example

int epfd = epoll_create1(EPOLL_CLOEXEC);
if (epfd < 0) {
    perror("epoll_create1");
}

Common Pitfalls

  • Prefer EPOLL_CLOEXEC to avoid leaking the fd across exec().
  • Close the epoll fd during cleanup.
  • epoll_create() is older; prefer epoll_create1() for new code.