Bug 53288 - tail(1) will sometimes display more lines than it is told
Summary: tail(1) will sometimes display more lines than it is told
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-13 20:10 UTC by hburch
Modified: 2018-01-03 05:13 UTC (History)
0 users

See Also:


Attachments
tail.1 (625 bytes, text/plain)
2004-01-14 12:11 UTC, Friedemann Becker
no flags Details
tail.1 (625 bytes, text/plain)
2004-01-14 12:19 UTC, Friedemann Becker
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description hburch 2003-06-13 20:10:14 UTC
tail will sometimes output more lines than it is told if the file is
being appended to.  I believe this is occurs when data is written
to the file after tail computes where to start displaying data,
but before the display starts.

Fix: 

No known fix.  tail could declare the end of the file (when -f is not
done) to be the length of the file when it first touches it, but that
could cause additional problems.
How-To-Repeat: Run one program that continuously prints out lines to a file:
	while [ 1 ]; do echo test; done > file
While that is running, run a bunch of tails and compute their length
	for i in `seq 1 1000`; do tail file | wc -l | done > linecnt
(In case it's not clear from the name, seq prints out 1 through 1000)
Look at the distribution of the line counts that were displayed:
 	sort -n linecnt | uniq -c

On my run:
 975       10
   1       61
   1       68
   1      118
   1      131
   1      134
   2      138
   1      168
   2      170
   1      174
   1      205
   1      227
   1      235
   1      259
   1      291
   1      348
   1      362
   1      367
   1      797
   1     1170
   1     1562
   1     2198
   1     5738
   1     5861
Comment 1 Friedemann Becker 2003-12-25 19:48:03 UTC
in How-To-Repeat it should be

while [ 1 ]; do echo test; done > file

and

for i in `jot 1000 1`; do tail file | wc -l; done > linecnt


(
 - freebsd uses jot, seq is gnu and if you install it via the port 
/usr/ports/misc/sh-utils you have to invoke it with 'gseq'
 - semikolon before done
)


I have got an easy workaround for it:

if a file is written to (or could be) while you want to 'tail' it, just 
do an
cat file | tail
that gives tail a snapshot of the file and the results of the above test 
are correct.

but someone should document this in man1/tail.1
Comment 2 Friedemann Becker 2004-01-14 12:11:56 UTC
I wrote this little note for the tail.1 manpage.
I am still new to this and I'm not sure, if this should be mentioned in
the manpage or not.
If the text is ok, please someone proofread and maybe commit it.
Otherwise, some commentary would be nice.
thanks


Comment 3 Friedemann Becker 2004-01-14 12:19:45 UTC
I wrote this little note for the tail.1 manpage.
I am still new to this and I'm not sure, if this should be mentioned in
the manpage or not.
If the text is ok, please someone proofread and maybe commit it.
Otherwise, some commentary would be nice.
thanks


Comment 4 Edwin Groothuis freebsd_committer freebsd_triage 2008-08-04 13:07:55 UTC
Responsible Changed
From-To: freebsd-bugs->edwin

Grab.
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:58 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped