File System - Watcher

Undraw File Manager Re Ms29

About

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

They are used generally to start a process such as:

Platform

Client Application

Linux

Select and poll

from wiki/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





Discover More
Gulp - Watch and Reload a Node Server

This page shows showcase how to reload a node http server with the watch possibility of gulp Below is an example of gulp.esm.js file that show case how to do it. You can adapt it to your situation....



Share this page:
Follow us:
Task Runner