epoll file descriptor operations

1.9k Views Asked by At

I'm trying to wrap my head around epoll in Linux.
The normal operation seems to be:

// Create the epoll_fd
int epoll_fd = epoll_create(10);

...

// Add file descriptors to it
struct epoll_event ev = {0};
ev.events |= EPOLLIN;
ev.data.ptr = ...;

/* for brevity, I don't do error checking here */
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, some_fd, &ev);

...

// Wait for IO events
struct epoll_event events[10];
int num_events = epoll_wait(epoll_fd, events, 10, -1);

// Now handle the events
...

My question is this: given the epoll_fd seems to be a regular file descriptor, are there any other file operations that I can do with it, besides the three epoll function calls?

2

There are 2 best solutions below

2
On

From the man page:

Q3 Is the epoll fd itself poll/epoll/selectable?

A3 Yes.

0
On

You can poll(2) your epoll_fd itself :)