Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tail -f always use inotify?

Tags:

linux

tail

I am using tail -f (on Linux) and am trying to figure out how I should use the -s parameter to set the polling interval. A colleague told me that -s0 would cause tail to use inotify instead of polling but I cannot find that in the documentation for tail.

The binary files I am tailing change constantly - does this suggest I should use -s0 or some fraction of second (like -s0.1) instead?

like image 985
Kevin Olree Avatar asked Jul 28 '15 20:07

Kevin Olree


People also ask

Does Tail use inotify?

No, tail -f does not always use inotify . inotify is not always available. Even if your kernel supports it, only a limited number of handles are available for watching files with inotify, and they may be in use somewhere else.

What is inotify used for?

Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

Does GIT use inotify?

Basically, gitwatch is an extended version of the bash script from above, and also uses the inotify kernel subsystem.

Does inotify work with NFS?

The inotify interface does have limitations—it can't monitor remote, network-mounted filesystems (that is, NFS); it does not report the userid involved in the event; it does not work with /proc or other pseudo-filesystems; and mmap() operations do not trigger it, among other concerns.


1 Answers

No, tail -f does not always use inotify.

inotify is not always available. Even if your kernel supports it, only a limited number of handles are available for watching files with inotify, and they may be in use somewhere else. Moreover, if any file in the list of names passed to tail is not on a local filesystem, polling will be used unconditionally.

The smart thing to do here is to trust the maintainers to have configured default behavior to be appropriately tuned for a reasonable balance of efficiency and performance, and avoid second-guessing. This is doubly so since (lacking clearly documented semantics around behavior with -s 0) any advice we gave here could become out-of-date in future releases.


Regardless: If your system does in fact support inotify, you'll be seeing lower latency than the default one-second polling period would suggest already, out-of-the-box, with no tuning or non-default options needed.

See the actual delay loop used for tail -f with inotify available; you'll see that the time passed with -s is given as a timeout to the select() call, but that this timeout is only reached if inotify does not return any events prior to that point.

like image 100
Charles Duffy Avatar answered Oct 14 '22 06:10

Charles Duffy