简体   繁体   English

tail -f始终显示“已杀死”

[英]tail -f always displays “Killed”

When doing 做的时候

tail -f /var/log/apache2/access.log

It shows logs and then 它显示日志,然后

Killed

I have to re-execute tail -f to see new logs. 我必须重新执行tail -f才能查看新日志。

How do I make tail -f continually display logs without killing itself? 如何使tail -f连续显示日志而不杀死自己?

The first thing I'd do is try --follow instead of -f. 我要做的第一件事是尝试--follow而不是-f。 Your problem could be happening because your log file is being rotated out. 您的问题可能是由于日志文件被轮换出来而发生的。 From the man page: 从手册页:

With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. 使用--follow(-f),tail默认为遵循文件描述符,这意味着即使重命名具有tail的文件,tail仍将继续跟踪其结尾。 This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (eg, log rotation). 当您确实要跟踪文件的实际名称而不是文件描述符(例如,日志轮换)时,这种默认行为是不可取的。 Use --follow=name in that case. 在这种情况下,请使用--follow = name。 That causes tail to track the named file in a way that accommodates renaming, removal and creation.* 这会导致tail以适应重命名,删除和创建的方式跟踪命名文件。*

tail -f should not get killed. tail -f不应该被杀死。

Btw, tail does not kill itself, it is killed by something. 顺便说一句,尾巴不会杀死自己,它会被某种东西杀死。 For example system is out of memory or resource limit is too restrictive. 例如系统内存不足或资源限制太严格。

Please figure out what kills your tail, using for example gdb or strace . 请使用gdbstrace找出导致您的尾巴被杀死的原因。 Also check your environment, at least ulimit -a and dmesg for any clues. 还要检查您的环境,至少检查ulimit -admesg是否有任何线索。

If your description is correct, and tail actually displays 如果您的描述正确,并且实际上显示了尾巴

Killed

then it is probably not happening as a result of log rotation. 那么它可能不会因日志轮换而发生。 Log rotation will causes tail to stop displaying new lines, but even if the file is deleted, tail will not be killed. 日志轮换将导致tail停止显示新行,但是即使文件被删除,tail也不会被杀死。

Rather, some other process on the system, or perhaps the kernel, is sending it a signal 9 (SIGKILL). 相反,系统上的某些其他进程(也许是内核)正在向其发送信号9(SIGKILL)。 Possible causes for this include: 可能的原因包括:

  • A user in another terminal issuing a command such as kill -9 1234 or pkill -9 tail 另一个终端中的用户发出诸如kill -9 1234pkill -9 tail

  • Some other tool or daemon (although I can't think of any that would do this) 其他一些工具或守护程序(尽管我想不出能做到这一点的任何工具)

  • The kernel itself can send SIGKILL to your process. 内核本身可以将SIGKILL发送到您的进程。 One scenario under which it would do this is if the OOM (Out of memory) killer kicked in. This happens when all RAM and swap in the system is used. 一种执行此操作的方案是踢出OOM(内存不足)杀手。当使用系统中的所有RAM和交换时,就会发生这种情况。 The kernel will select a process which is using a lot of memory and kill it. 内核将选择一个占用大量内存的进程并杀死它。 If this was happening it would be visible in syslog, but it is quite unlikely that tail would use that much memory. 如果发生这种情况,它将在syslog中可见,但是tail不太可能使用那么多内存。

  • The kernel can send you SIGKILL if RLIMIT_CPU (the limit on the amount of CPU time your process has used) is exceeded. 如果超过了RLIMIT_CPU(进程已使用的CPU时间的限制),则内核可以向您发送SIGKILL。 If you leave tail running for long enough, and you have a ulimit set, then this can happen. 如果您将尾巴运行了足够长的时间,并且设置了ulimit,则可能会发生这种情况。 To check for this (and other resource limitations) use ulimit -a 要检查此限制(以及其他资源限制),请使用ulimit -a

In my opinion, either the first or last of these explanations seems most likely. 我认为,这些解释中的第一个或最后一个似乎都是最有可能的。

您需要使用tail -F logfile ,如果日志文件旋转,它将不会终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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