[svlug] select/poll and EOF
scott at doubleu.com
Thu Aug 14 22:18:12 PDT 2003
Does it need to be a real file, or similar to a file? If you can live
with a named pipe (aka fifo), then select() should work. mknod(1) to
create (or mknod(2), of course), then open for reading and run your
select() loop as normal, and have the other side write to it.
The main downside is that it's not seekable, and most file-oriented
commands are going to bail when they get the 0 return from read(2) when
they run out of input. But if you're writing your own...
On Fri, 15 Aug 2003, M. Drew Streib wrote:
> Another question...
> I need to implement something similar to 'tail -f' although it needs
> to have millisecond accuracy.
> select() and poll() both return on a file EOF, because read() will not
> block. I need to either get one of them to not return on an EOF, but
> rather when there is actual data to read, or accomplish the same thing
> in another manner.
> This question has been asked and badly answered on lkml before. (Not
> a real answer, only an explanation of why select() does what it does.
> I know what it does, dammit. :) I need to know how to get something
> else done. heh.)
> It turns out GNU tail just cheeses things and only checks the file
> descriptor once per second for changes. In my case, this won't work
> well as I'd like to know when data is available immediately.
> My only recourse now is to basically sleep for some fraction of a
> second and then do a read() to see what returns. The more accurate
> I want to get, though, the more I send the cpu(s) into frantic cycles
> for no reason.
> Any ideas? I'm beginning to think I'm just SOL.
More information about the svlug