I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script?
I think dd
is your friend:
dd if=myfifo iflag=nonblock of=/dev/null
strace shows
open("myfifo", O_RDONLY|O_NONBLOCK)
and indeed doesn't even block on an empty fifo.