0

How does a tool like grep know when the end of file is reached, when reading from stdin (like in foo | grep)?

The EOF byte could belong to the original file, so it can't rely on that. Does it rely on the fact that the pipe is closed or something else?

AdminBee
  • 21,637
  • 21
  • 47
  • 71
hehehe
  • 13
  • 2
  • 2
    Tangentially related: [What's the last character in a file?](https://unix.stackexchange.com/questions/315151/whats-the-last-character-in-a-file) – steeldriver Dec 25 '21 at 19:20
  • 1
    ... perhaps you will find this useful as well: [When does piped command stop?](https://unix.stackexchange.com/questions/417041/when-does-piped-command-stop) – steeldriver Dec 25 '21 at 20:44
  • 1
    There is no "EOF Byte" in Unix/Linux. When the producing process exits, its files are closed. When the consuming process sees the closed file (after consuming the rest of the data) it sets an EOF condition. – waltinator Dec 25 '21 at 23:08

0 Answers0