EOF
is not a character nor an "event" and could not be sent through the pipe, or "fed" to its writing end, as some stubborn urban legend suggests.
The only way to generate an EOF
on the reading end of a pipe/fifo (ie cause a read(2)
on it to return 0) is to close all open handles to its writing end.
This will happen automatically if all the processes that had opened a named pipe in write mode and all the children that have inherited the file descriptors through fork()
are terminated [1].
It's not possible for a read(2)
on a named pipe to return 0 it that pipe was opened in read/write mode, eg. with
exec 7<>/path/to/fifo
because in that case there is a single file descriptor / handle for both ends of the pipe and closing the write end will also close the read end making impossible for a read(2)
to return 0 (pipes do not support any kind of half-close as sockets do with shutdown(2)
).
[1] And all processes that have received the file descriptor via SCM_RIGHTS
ancillary message on a unix socket.
Notice that tail -f
by definition won't terminate upon EOF
, whether the file it's reading from is regular or special. One way to kill all processes that are holding a open handle to a file descriptor is with fuser(1)
:
tail -f /path/to/fifo
...
> /path/to/fifo # let any blocking open(2) through
fuser -TERM -k /path/to/fifo
Beware that this will also kill processes that have (inadvertently) inherited an open handle to /path/to/fifo
from their parents.
EOF
into the input side of the pipe,tail
will see it and close its end. This should normally happen automagically when whatever had been writing to the pipe was done. Remember to clean up after yourself andrm
what you hadmkfifo
ed earlier.tail -f
is that it ignores any suggestion that it has reached the end of the file (or pipe); it will wait forever for someone to reopen the file and start writing to it again. Compare with something likecat MYNAMEDPIPE
, which will block until something writes to it, but will indeed exit once the writer closes its end and all remaining data has been read.cat <<EOF > MYNAMEDPIPED
?tail -f
is to send a signal to it, e.g. withkill
.