Debian Codegraph @

README

raw
1 <p align="center">
2 <a href="https://emcrisostomo.github.io/fswatch/">
3 <img src="https://emcrisostomo.github.io/fswatch/images/fswatch-logo.svg" alt="fswatch logo" width="128">
4 </a>
5 </p>
6
7 [![License](https://img.shields.io/badge/license-GPL--3.0-blue.svg?style=flat)](https://github.com/emcrisostomo/fswatch/blob/master/COPYING)
8 [![C/C++ CI](https://github.com/emcrisostomo/fswatch/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/emcrisostomo/fswatch/actions/workflows/c-cpp.yml)
9 [![CMake](https://github.com/emcrisostomo/fswatch/actions/workflows/cmake.yml/badge.svg)](https://github.com/emcrisostomo/fswatch/actions/workflows/cmake.yml)
10
11 README
12 ======
13
14 `fswatch` is a file change monitor that receives notifications when the contents
15 of the specified files or directories are modified. `fswatch` implements
16 several monitors:
17
18 * A monitor based on the _File System Events API_ of Apple macOS.
19 * A monitor based on _kqueue_, a notification interface introduced in FreeBSD
20 4.1 (and supported on most *BSD systems, including macOS).
21 * A monitor based on the _File Events Notification_ API of the Solaris kernel
22 and its derivatives.
23 * A monitor based on _inotify_, a Linux kernel subsystem that reports file
24 system changes to applications.
25 * A monitor based on _fanotify_, a Linux kernel subsystem that reports file
26 system events to applications.
27 * A monitor based on _ReadDirectoryChangesW_, a Microsoft Windows API that
28 reports changes to a directory.
29 * A monitor which periodically stats the file system, saves file modification
30 times in memory, and manually calculates file system changes (which works
31 anywhere `stat (2)` can be used).
32
33 `fswatch` should build and work correctly on any system shipping either of the
34 aforementioned APIs.
35
36 Table of Contents
37 -----------------
38
39 * [libfswatch](#libfswatch)
40 * [Features](#features)
41 * [Limitations](#limitations)
42 * [Getting fswatch](#getting-fswatch)
43 * [Building from Source](#building-from-source)
44 * [Installation](#installation)
45 * [Documentation](#documentation)
46 * [Localization](#localization)
47 * [Usage](#usage)
48 * [Contributing](#contributing)
49 * [Bug Reports](#bug-reports)
50
51 libfswatch
52 ----------
53
54 `fswatch` is a frontend of `libfswatch`, a library with C, C++ and
55 [Go][go.binding] bindings. More information on `libfswatch` can be found
56 [here][README.libfswatch.md].
57
58 [go.binding]: https://github.com/dunglas/go-fswatch
59 [README.libfswatch.md]: README.libfswatch.md
60
61 Features
62 --------
63
64 `fswatch` main features are:
65
66 * Support for many OS-specific APIs such as kevent, inotify, and FSEvents.
67 * Recursive directory monitoring.
68 * Path filtering using including and excluding regular expressions, with
69 legacy and conjunctive evaluation modes.
70 * Customizable record format.
71 * Support for periodic idle events.
72
73 Limitations
74 -----------
75
76 The limitations of `fswatch` depend largely on the monitor being used:
77
78 * The **FSEvents** monitor, available only on macOS, has no known limitations,
79 and scales very well with the number of files being observed.
80
81 * The **File Events Notification** monitor, available on Solaris kernels and
82 its derivatives, has no known limitations.
83
84 * The **kqueue** monitor, available on any \*BSD system featuring kqueue,
85 requires a file descriptor to be opened for every file being watched. As a
86 result, this monitor scales badly with the number of files being observed,
87 and may begin to misbehave as soon as the `fswatch` process runs out of file
88 descriptors. In this case, `fswatch` dumps one error on standard error for
89 every file that cannot be opened.
90
91 * The **inotify** monitor, available on Linux since kernel 2.6.13, may suffer
92 from several limitations. It provides no information about the user or
93 process that triggered an event, so it cannot easily distinguish events it
94 triggers itself from those triggered by other processes. It reports only
95 events triggered through the filesystem API, so it does not catch remote
96 events on network filesystems and cannot monitor pseudo-filesystems such as
97 `/proc`, `/sys`, or `/dev/pts`. It also does not report accesses or
98 modifications that occur through `mmap(2)`, `msync(2)`, or `munmap(2)`.
99 Events identify files by name, but the name may already have been deleted
100 or renamed by the time the application handles the event. Events are also
101 identified by watch descriptors, so applications must cache a mapping to
102 pathnames if they need one, and directory renames can affect several cached
103 pathnames at once. Inotify monitoring of directories is not recursive, so
104 additional watches must be created for subdirectories, and that can take a
105 significant amount of time on large trees. If a new subdirectory appears
106 or is renamed into a monitored tree, the application may need to rescan it
107 immediately after adding the watch so that it does not miss children that
108 already exist. The event queue can overflow, in which case events are lost
109 and robust applications may need to rebuild some or all of their cache.
110 Finally, if a filesystem is mounted on top of a monitored directory, no
111 event is generated until the filesystem is unmounted again.
112
113 * The **fanotify** monitor, available on Linux since kernel 2.6.37, reports
114 only events triggered through the filesystem API, so it does not catch
115 remote events on network filesystems. It also does not report accesses or
116 modifications that occur through `mmap(2)`, `msync(2)`, or `munmap(2)`.
117 Directory events are generated only when the directory itself is opened,
118 read, and closed, so adding, removing, or changing children does not create
119 events for the monitored directory itself. Fanotify monitoring of
120 directories is not recursive: subdirectories require additional marks, and
121 using `FAN_CREATE` to detect them is racy because events may be lost before
122 the new mark is added. Monitoring mounts or entire filesystems avoids this
123 race. The event queue can also overflow, in which case events are lost.
124
125 * The **Windows** monitor can only establish a watch _directories_, not files.
126 To watch a file, its parent directory must be watched in order to receive
127 change events for all the directory's children, _recursively_ at any depth.
128 Optionally, change events can be filtered to include only changes to the
129 desired file.
130
131 * The **poll** monitor, available on any platform, only relies on
132 available CPU and memory to perform its task. The performance of this
133 monitor degrades linearly with the number of files being watched.
134
135 Usage recommendations are as follows:
136
137 * On macOS, use only the `FSEvents` monitor (which is the default behaviour).
138
139 * On Solaris and its derivatives use the _File Events Notification_ monitor.
140
141 * On Linux, use the `inotify` monitor (which is the default behaviour).
142
143 * If the number of files to observe is sufficiently small, use the `kqueue`
144 monitor. Beware that on some systems the maximum number of file descriptors
145 that can be opened by a process is set to a very low value (values as low as
146 256 are not uncommon), even if the operating system may allow a much larger
147 value. In this case, check your OS documentation to raise this limit on
148 either a per process or a system-wide basis.
149
150 * If feasible, watch directories instead of files. Properly crafting the
151 receiving side of the events to deal with directories may sensibly reduce
152 the monitor resource consumption.
153
154 * On Windows, use the `windows` monitor.
155
156 * If none of the above applies, use the poll monitor. The authors' experience
157 indicates that `fswatch` requires approximately 150 MB of RAM memory to
158 observe a hierarchy of 500.000 files with a minimum path length of 32
159 characters. A common bottleneck of the poll monitor is disk access, since
160 `stat()`-ing a great number of files may take a huge amount of time. In
161 this case, the latency should be set to a sufficiently large value in order
162 to reduce the performance degradation that may result from frequent disk
163 access.
164
165 Getting fswatch
166 ---------------
167
168 A regular user may be able to fetch `fswatch` from the package manager of your
169 OS or a third-party one. If you are looking for `fswatch` for macOS, you can
170 install it using either [MacPorts] or [Homebrew]:
171
172 ```
173 # MacPorts
174 $ port install fswatch
175
176 # Homebrew
177 $ brew install fswatch
178 ```
179
180 On FreeBSD, `fswatch` can be installed using [pkg]:
181
182 ```console
183 # pkg install fswatch-mon
184 ```
185
186 Check your favourite package manager and let us know if `fswatch` is missing
187 there.
188
189 [MacPorts]: https://www.macports.org
190 [Homebrew]: http://brew.sh
191 [pkg]: https://man.freebsd.org/pkg/8
192
193 Building from Source
194 --------------------
195
196 A user who wishes to build `fswatch` should get a [release tarball][release].
197 A release tarball contains everything a user needs to build `fswatch` on their
198 system, following the instructions detailed in the Installation section below
199 and the `INSTALL` file.
200
201 A developer who wishes to modify `fswatch` should get the sources (either from a
202 source tarball or cloning the repository) and have the GNU Build System
203 installed on their machine. Please read `README.gnu-build-system` to get
204 further details about how to bootstrap `fswatch` from sources on your machine.
205
206 Getting a copy of the source repository is not recommended unless (i) you are a
207 developer, (ii) you have the GNU Build System installed on your machine, and
208 (iii) you know how to bootstrap it on the sources.
209
210 CMake-support is unofficially offered as a courtesy.
211
212 On Windows, MSYS2 with a MinGW-w64 toolchain is the recommended build
213 environment. Cygwin builds are kept for compatibility, but Cygwin is not
214 required to build `fswatch` on Windows. See `README.windows` for details.
215
216 [release]: https://github.com/emcrisostomo/fswatch/releases
217
218 Installation
219 ------------
220
221 See the `INSTALL` file for detailed information about how to configure and
222 install `fswatch`. Since the `fswatch` builds and uses dynamic libraries, in
223 some platforms you may need to perform additional tasks before you can use
224 `fswatch`:
225
226 * Make sure the installation directory of dynamic libraries (`$PREFIX/lib`) is
227 included in the lookup paths of the dynamic linker of your operating system.
228 The default path, `/usr/local/lib`, will work in nearly every operating
229 system.
230 * Refreshing the links and cache to the dynamic libraries may be required. In
231 GNU/Linux systems you may need to run `ldconfig`:
232
233 $ ldconfig
234
235 `fswatch` is a C++ program and a C++ compiler compliant with the C++ standard
236 currently used is required.
237
238 As of version 1.17.1 included, `fswatch` has required a C++11-compliant
239 compiler. Subsequent versions require a C++17-compliant compiler. Check your
240 OS documentation for information about how to install the C++ toolchain and the
241 C++ runtime.
242
243 No other software packages or dependencies are required to configure and install
244 `fswatch` but the aforementioned APIs used by the file system monitors.
245
246 Documentation
247 -------------
248
249 `fswatch` provides the following [documentation]:
250
251 * Texinfo documentation, included with the distribution.
252 * HTML documentation.
253 * PDF documentation.
254 * The [GitHub website].
255 * A man page.
256
257 `fswatch` official documentation is provided in Texinfo format. This is the
258 most comprehensive source of information about `fswatch` and the only
259 authoritative one. The man page, in particular, is a stub that suggests the
260 user to use the info page instead.
261
262 The project website also provides maintained online documentation and release
263 resources.
264
265 If you are installing `fswatch` using a package manager and you would like the
266 PDF manual to be bundled into the package, please send a feature request to the
267 package maintainer.
268
269 [documentation]: https://emcrisostomo.github.io/fswatch/documentation.html
270 [GitHub website]: https://emcrisostomo.github.io/fswatch/
271
272 Localization
273 ------------
274
275 `fswatch` is localizable and internally uses GNU `gettext` to decouple
276 localizable string from their translation. The currently available locales are:
277
278 * English (`en`).
279 * Italian (`it`).
280 * Spanish (`es`).
281
282 To build `fswatch` with localization support, you need to have `gettext`
283 installed on your system. If `configure` cannot find `<libintl.h>` or the
284 linker cannot find `libintl`, then you may need to manually provide their
285 location to `configure`, usually using the `CPPFLAGS` and the `LDFLAGS`
286 variables. See `README.macos` for an example.
287
288 If `gettext` is not available on your system, `fswatch` shall build correctly,
289 but it will lack localization support and the only available locale will be
290 English.
291
292 Usage
293 -----
294
295 `fswatch` accepts a list of paths for which change events should be received:
296
297 $ fswatch [options] ... path-0 ... path-n
298
299 The event stream is created even if any of the paths do not exist yet. If they
300 are created after `fswatch` is launched, change events will be properly
301 received. Depending on the watcher being used, newly created paths will be
302 monitored after the amount of configured latency has elapsed.
303
304 The output of `fswatch` can be piped to other program in order to process it
305 further:
306
307 $ fswatch -0 path | while read -d "" event
308 do
309 # do something with ${event}
310 done
311
312 To run a command when a set of change events is printed to standard output but
313 no event details are required, then the following command can be used:
314
315 $ fswatch -o path | xargs -n1 -I{} program
316
317 The behaviour is consistent with earlier versions of `fswatch` (v. 0.x).
318 Please, read the _Compatibility Issues with fswatch v. 0.x_ section for further
319 information.
320
321 By default `fswatch` chooses the best monitor available on the current platform,
322 in terms of performance and resource consumption. If the user wishes to specify
323 a different monitor, the `-m` option can be used to specify the monitor by name:
324
325 $ fswatch -m kqueue_monitor path
326
327 The list of available monitors can be obtained with the `-h` option.
328
329 For more information, refer to the `fswatch` documentation.
330
331 Contributing
332 ------------
333
334 Everybody is welcome to contribute to `fswatch`. Please, see
335 [`CONTRIBUTING`][contrib] for further information.
336
337 [contrib]: CONTRIBUTING.md
338
339 Bug Reports
340 -----------
341
342 Bug reports can be sent directly to the authors.
343
344 Contact the Authors
345 -------------------
346
347 The author can be contacted on IRC, using the Freenode `#fswatch` channel.
348
349 License
350 -------
351
352 This software is dual-licensed under the GPL v. 3.0 and the Apache License
353 v. 2.0.
354
355 -----
356
357 Copyright (c) 2013-2026 Enrico M. Crisostomo
358
359 This program is free software; you can redistribute it and/or modify it under
360 the terms of the GNU General Public License as published by the Free Software
361 Foundation; either version 3, or (at your option) any later version.
362
363 This program is distributed in the hope that it will be useful, but WITHOUT ANY
364 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
365 PARTICULAR PURPOSE. See the GNU General Public License for more details.
366
367 You should have received a copy of the GNU General Public License along with
368 this program. If not, see <http://www.gnu.org/licenses/>.