[英]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. 我正在使用tail -f(在Linux上),并试图弄清楚应该如何使用-s参数设置轮询间隔。 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.
一位同事告诉我-s0会导致tail使用inotify而不是轮询,但是我在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? 我要跟踪的二进制文件不断变化-这是否表明我应该使用-s0或几分之一秒(例如-s0.1)呢?
No, tail -f
does not always use inotify
. 不,
tail -f
并不总是使用inotify
。
inotify
is not always available. inotify
并非始终可用。 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. 即使您的内核支持它,也只能使用有限数量的句柄来监视具有inotify的文件,并且它们可能在其他地方使用。 Moreover, if any file in the list of names passed to
tail
is not on a local filesystem, polling will be used unconditionally. 而且,如果传递给
tail
的名称列表中的任何文件都不在本地文件系统上,则将无条件使用轮询。
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. 这是双重的,因为(缺少关于
-s 0
行为的明确记录的语义),我们在此处给出的任何建议在将来的发行版中都可能会过时。
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. 无论如何:如果您的系统实际上确实支持inotify,您将看到比默认的一秒轮询周期更低的延迟,即开箱即用,不需要调整或非默认选项。
See the actual delay loop used for tail -f
with inotify available ; 参见用于
tail -f
的实际延迟循环,并提供inotify ; 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. 您会看到
-s
传递的时间作为select()调用的超时,但是只有inotify在该点之前不返回任何事件时才达到此超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.