Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between inotify and epoll

I would like to know what the difference is between both i/o watchers inotify and epoll?

inotify

  • inotify_init(void) creates inotify instance to read events from
  • inotify_add_watch(int fd, const char * path, int mask) returns a watch fd around the file node behind the path
  • inotify_rm_watch(int fd, int wd) stops watching for events on fd

epoll

  • epoll_create(void) creates epoll object
  • epoll_ctl(int epfd, int op, int fd, struct epoll_event * event) sets up events to watch
  • epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); blocks until event happens

So there seems to be a different approach on file watching. Inotify tries to let the user decide when to collect events while epoll blocks until something happens.

Is this correct? What are other differences?

like image 348
bodokaiser Avatar asked Jun 20 '13 07:06

bodokaiser


People also ask

What is epoll used for?

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() is a control function that allows us to add descriptors to a watch set, remove descriptors from a watch set, or reconfigure file descriptors already in the watch set. epoll_wait() waits for I/O events on the watch set, blocking the calling thread until one or more events are detected.

What are epoll events?

epoll stands for event poll and is a Linux specific construct. It allows for a process to monitor multiple file descriptors and get notifications when I/O is possible on them. It allows for both edge-triggered as well as level-triggered notifications.


1 Answers

The biggest difference is that epoll can be used for ANY fd. This means it's good for watching all types of ways to communicate data. Sockets, IPC, files, printers.. anything. inotify is for filesystems only.

However, because inotify is specific to filesystems, you can receive notifications on a wide array of filesystem-specific attributes, such as file attributes and the file being read. These things are not possible via epoll.

In fact, inotify returns a file descriptor - which means you can use epoll to determine which inotify FD's you should call read on. So the two go hand in hand to some extent.

http://en.wikipedia.org/wiki/Inotify

like image 132
xaxxon Avatar answered Sep 19 '22 19:09

xaxxon