简体   繁体   中英

Does tail -f always use inotify?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM