Here is the situation : Some process writes lines into a fifo file (created with mkfifo). At some point in my program, I want to read the last line in the fifo, and discard all the others. The procedure may block, only if there is less than one line in the fifo.
I can’t come up with a clean way to do this, any ideas ?
EDIT : The writing process will never stop writing lines into the fifo, What I mean by the last line is the last by the time I read the fifo. It is not necessarily followed by a EOF.
If your main concern is that the read will block then open the FIFO as non-blocking. I assume you know what you are looking for in the stream and will simply discard everything before.
You can also use something like select() to be informed when there is something to read off the pipe.