Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Epoll on regular files

People also ask

Does epoll work on files?

Not really. epoll only makes sense for file descriptors which would normally exhibit blocking behavior on read/write, like pipes and sockets. Normal file descriptors will always either return a result or end-of-file more or less immediately, so epoll wouldn't do anything useful for them.

What is an epoll file descriptor?

epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5. 44 of the Linux kernel. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them.

What is epoll socket?

epoll_ctl with EPOLL_CTL_ADD should be called once for each socket. And when epoll_wait is called, it will monitor all the sockets that are added and return only those FDs that have some events to consume.


Not really. epoll only makes sense for file descriptors which would normally exhibit blocking behavior on read/write, like pipes and sockets. Normal file descriptors will always either return a result or end-of-file more or less immediately, so epoll wouldn't do anything useful for them.


I think, it will fail at epoll_ctl with EPERM:

   EPERM  The target file fd does not support epoll.

if the file has no poll() interface.

The actual code is http://lxr.linux.no/#linux+v3.1/fs/eventpoll.c#L1373

1373    /* The target file descriptor must support poll */
1374        error = -EPERM;
1375        if (!tfile->f_op || !tfile->f_op->poll)
1376                goto error_tgt_fput;
1377