File System - Watcher

About

A watcher detect a change of state for a file and emits an event.

Platform

Client

Linux

Select and poll

from Event_loop

The select and poll system calls allow a set of file descriptors to be monitored for a change of state, e.g. when data becomes available to be read.

main():
    file_fd = open ("logfile")
    x_fd = open_display ()
    construct_interface ()
    while changed_fds = select ({file_fd, x_fd}):
        if file_fd in changed_fds:
            data = read_from (file_fd)
            append_to_display (data)
            send_repaint_message ()
        if x_fd in changed_fds:
            process_x_messages ()

inotify

File system watcher requires inotify(7) facility. The sign of inotify availability in a system is a presence of /proc/sys/fs/inotify/ directory.

File system watcher is a single binary executable (fsnotifier) and can be downloaded directly from our Git repository.

cat /proc/sys/fs/inotify/max_user_watches

It can be raised by adding following line to the /etc/sysctl.conf file:

fs.inotify.max_user_watches = 524288

… and issuing this command to apply the change:

sudo sysctl -p

Java

Nio has a watcher. Example: Vertx watcher

Documentation / Reference


Powered by ComboStrap