Timeline for Why does `tail -c 4097 /dev/zero` exit immediately instead of blocking?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 17 at 8:35 | vote | accept | Isidro Arias | ||
| Apr 16 at 22:17 | history | became hot network question | |||
| Apr 16 at 21:53 | answer | added | Stephen Kitt | timeline score: 10 | |
| Apr 16 at 13:50 | comment | added | terdon♦ |
Hmm yes, but it seems to have a different buffer (presumably, there's some buffer somewhere involved since the numbers on Ubuntu are so specific), as both busybox tail -c 4097 /dev/zero and busybox tail -c 4096 /dev/zero hang though.
|
|
| Apr 16 at 13:06 | comment | added | muru | Busybox tail does hang with the same arguments that cause GNU tail exit immediately on my Arch Linux system | |
| Apr 16 at 12:49 | history | edited | terdon♦ | CC BY-SA 4.0 |
added 60 characters in body
|
| Apr 16 at 11:41 | comment | added | ilkkachu |
I forgot to say, I got what the post above shows with tail from GNU coreutils 8.32 on Ubuntu, but I suspect this could depend very much on the implementation, since something like /dev/zero is a bit of an oddball case.
|
|
| Apr 16 at 11:28 | comment | added | terdon♦ |
Ah, right, yes. I see what you mean, thanks @ilkkachu. Weird then, both 4096 and 4097 return exactly 4096 or 4097 bytes and exit on my Arch. Same with /dev/random and /dev/urandom.
|
|
| Apr 16 at 11:20 | comment | added | ilkkachu |
@terdon, they said it there: "since /dev/zero is an endless stream". tail -c is supposed to print the last N bytes, but you can't find the "last" bytes of an endless stream. Of course, when reading from a seekable file (instead of a pipe), tail could just seek to the correction position, and read the requested amount, which that strace shows it doing, and the seek even succeeds. But why does the requested amount of bytes change what it does after, who knows.
|
|
| Apr 16 at 10:51 | comment | added | terdon♦ |
Why would you expect this to hang instead of simply returning 4096 bytes and exiting? I don't know much about this kind of thing, but it seems odd to expect it to hang. What does tail -c 4097 /dev/zero | wc -c tell you? Doesn't it return 4097? It does on my Arch.
|
|
| S Apr 16 at 10:02 | review | First questions | |||
| Apr 16 at 10:05 | |||||
| S Apr 16 at 10:02 | history | asked | Isidro Arias | CC BY-SA 4.0 |