WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: tail -f appears to hang  (Read 1847 times)

Offline nurbles

  • Newbie
  • *
  • Posts: 46
tail -f appears to hang
« on: November 01, 2023, 09:38:19 AM »
I'm using Linux version 6.1.2-tinycore64 (tc@box) (gcc (GCC) 12.2.0, GNU ld (GNU Binutils) 2.39) #612 SMP Mon Jan  2 17:24:30 UTC 2023 and the tail command isn't working correctly.  It logs between 100 and 200 lines and then just stops showing anything.  If I use Ctrl+C and restart the tail it works for another couple hundred lines or so.  The exact command I'm using is

tc@mybox:~$ tail -f /var/log/messages

I know that's correct and it works on my Ubuntu systems, so what could I be doing that is causing tail to stop writing anything to the display (or maybe stop reading the log)?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11705
Re: tail -f appears to hang
« Reply #1 on: November 01, 2023, 12:17:40 PM »
Hi nurbles
... It logs between 100 and 200 lines and then just stops showing anything. ...

I just tried this under TC14 x86_64 (6.1.2-tinycore64).

Opened a terminal and entered:
Code: [Select]
touch tail.txt
tail -f tail.txt

Opened a second terminal and entered:
Code: [Select]
seq 300 > tail.txt
All 300 entries showed up.
I did this with both busybox and GNU versions of tail.

I then upped the ante and did this:
Terminal #1
Code: [Select]
touch tail.txt
tail -f tail.txt | tee tail.mon
The results of tail get written to the screen and to tail.mon.

Terminal #1
Code: [Select]
seq 3000 > tail.txt
diff tail.txt tail.mon

All 3000 entries showed up.
The diff command showed both files were identical.
Once again, I did this with both busybox and GNU versions of tail.

Offline nurbles

  • Newbie
  • *
  • Posts: 46
Re: tail -f appears to hang
« Reply #2 on: November 01, 2023, 02:19:26 PM »
Yup.  Mine used to do the same.  This week it changed and I cannot figure out why.  I edited my project's source and recompiled, but that should definitely not affect how tail works.  That's why I'm asking for ideas on why tail might "stall" (for lack of a better term.)

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: tail -f appears to hang
« Reply #3 on: November 01, 2023, 03:21:54 PM »
Hi nurbles!
How much time does it take for "tail -f" to freeze? I guess not minutes but hours?
« Last Edit: November 01, 2023, 03:23:25 PM by jazzbiker »

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: tail -f appears to hang
« Reply #4 on: November 01, 2023, 04:38:42 PM »
The "tail" is loosing the track if file is removed and then reborn with the same name. Like
Code: [Select]
tc@box:~$ while true; do date >> abc; sleep 1; done &
in one terminal, then
Code: [Select]
tc@box tail -f abc
in another, then in the first one
Code: [Select]
tc@box:~$ jobs
[1]+  Running                    while true; do date 1>>abc; sleep 1; done
tc@box:~$ kill %1
tc@box:~$
[1]+  Terminated                 while true; do date 1>>abc; sleep 1; done
tc@box:~$ rm -f abc
tc@box:~$ while true; do date >> abc; sleep 1; done &
And "tail" in the second terminal stalls.
Isn't it Your case?
« Last Edit: November 01, 2023, 04:53:35 PM by jazzbiker »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11705
Re: tail -f appears to hang
« Reply #5 on: November 01, 2023, 05:28:05 PM »
Hi nurbles
jazzbikers comment joggedmy memory.

When  messages  gets filled up it gets moved to  messages.0  and
a new  messages  file gets created. That's probably when  tail  gets
hung up.

Try:
Code: [Select]
tail -F /var/log/messages
If that doesn't fix it, try:
Code: [Select]
tce-load -wi coreutils
hash -r
tail -F /var/log/messages


Offline nurbles

  • Newbie
  • *
  • Posts: 46
Re: tail -f appears to hang
« Reply #6 on: November 10, 2023, 08:39:57 AM »
First, sorry for my delay responding...another project required my attention.

Unfortunately, the tail command stops logging for me after roughly 50-100 lines.  If I hit Ctrl+C, the command prompt returns and I can re-enter my tail command.  The new tail command will also stop in 50-100 lines.  Repeat forever.  While I understand that tail would stop following the system log when syslog switches to a new file, I cannot believe this is happening every couple hundred lines.  Also, there is only /var/log/messages, no files named /var/log/messages.0 or any other suffix.

Thinking about it, what I'd really like would be to configure the syslog to also send everything to another system using UDP (e.g. by adding the line "*.* @192.168.1.1" to the config file).  I need to look into that as soon as I can get back to work on this project.  While the suggestions haven't solved my issue with tail -f, they have inspired a new idea, so thanks for that!  (smile)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11705
Re: tail -f appears to hang
« Reply #7 on: November 10, 2023, 09:17:17 AM »
Hi nurbles
Maybe it's an issue with the  busybox tail  command.

Did you try the GNU version of  tail  provided by  coreutils.tcz:
Code: [Select]
tce-load -wi coreutils
hash -r
tail -F /var/log/messages