How can I read keyboard without stopping

Leslie Mikesell les at chinet.UUCP
Tue Sep 20 03:00:08 AEST 1988


In article <12587 at ncoast.UUCP> allbery at ncoast.UUCP (Brandon S. Allbery) writes:

>...unless the pipe is really a FIFO, in which case the EOF is (again)
>temporary.  (That's how it seemed to work under SVR2, at least.  I would
>have preferred that the call block until someone else opened the other end
>of the FIFO and wrote to it, though, for the application I was trying to
>write with FIFOs.  It made the program work like it was in NDELAY mode.  I
>finally ended up using message queues.)

If you do not set NDELAY on a FIFO, the first read will block until something
is available, and the last close will make subsequent reads return EOF until
another process opens the FIFO for output.  If you want the reading process
to always block when no data is available, just have it open the FIFO for
write access (but don't write anything).  I use this trick to connect shell
scripts to FIFOs so I can periodically echo commands at them.  If I want
the script to be able to continue with something else when no command is
present, I don't open it for writing.  This is handy since you can't fcntl()
from a shell script but it would be nice if there were better documentation
about FIFOs.

Les Mikesell



More information about the Comp.unix.wizards mailing list