named pipes

Leslie Mikesell les at chinet.UUCP
Fri Apr 15 05:57:06 AEST 1988


In article <339 at bacchus> darren at bacchus (Darren Friedlein) writes:
>
>OK - Is there anyone out there that can explain to me how named pipes work
>(specifically on the UNIXpc)?  I understand the concept, but I don't know
>how to implement them.  I believe /dev/lp is one, but I'm not sure.  Does
>each one require a device driver?  Does the fact that I use the pty package
>make things any easier?
No, /dev/lp is not a named pipe...
ls -l will show the first character of the listing as a 'p' for anything
that is a named pipe (also known as a FIFO). /dev/lp is a 'c'haracter device.

Create a named pipe with:
mknod filename p
Then open/read/write redirected I/O and most of the other things that
work with files and unnamed pipes can be used with the following differences:

A read will block if there is no data available (controlled by O_NDELAY) and
a process has the file open for writing.  If the FIFO has been opened for
writing and no process currently has it open for writing, a read will
return EOF when there is no data.
A write will block until a process opens the FIFO for reading (again
controlled by O_NDELAY).

If you want to read the FIFO with a shell script without worrying about
EOF every time a process closes it, just make the same program also open the
FIFO for writing (even if you don't want to write to it).  This will
make all reads block until something writes to the FIFO.

  Les Mikesell
                 ...ihnp4!chinet!les



More information about the Unix-pc.general mailing list