Consultor Eletrônico



Kbase 16373: UNIX Named Pipes
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
UNIX Named Pipes

Named Pipes
INTRODUCTION
The purpose of this knowledge base entry is to serve as a
background for the companion entry titled Progress Named Pipes.

In order to use named pipes in Progress, you must first understand
how unix handles them. Named pipes are created by the unix command
mknod, or mkfifo and are used as an interprocess communication (ipc)
mechanism. When dealing with named pipes, there are processes that
read data from the pipe (readers), and processes that write data to
the pipe (writers). This is performed by the same system calls used
for I/O to regular files (open(), read(), write(), close() ...).
System calls such as lseek() which do not make sense for named pipes
will return an error status when used on such a file.

The operating system provides synchronization between the processes
accessing the named pipe depending on certain flags set by open().
The default synchronization mechanism, the mode used by Progress, has
the characteristics presented here. When a reader opens a named pipe
for input, it will block until a writer has opened the pipe for
output (and visa versa).

A writer is allowed to continually write data to the named pipe
until the named pipe file buffer (FIFO queue) is full. The size of
the FIFO queue is determined by the PIPE_BUF system parameter as
specified in /usr/include/sys/param.h. When the FIFO queue has
become full, the writer will block until a reader removes some data
from the FIFO queue. If the writer attempts to write to the named
pipe after the reader has closed it, the writer will receive a
"Broken Pipe error (EPIPE). The writer can close the pipe at any
time (there is no synchronization on close). The writer can also
reopen the pipe without blocking providing a reader still has the
pipe open. If no reader has the named pipe open, the operating
system synchronization mechanism will block the writer on open()
until a reader opens the named pipe.

After the reader has successfully opened the named pipe and issued
a read() system call, it will block until there is some data in the
FIFO queue for it to retrieve. The read() system call will retrieve
whatever data is in the queue up to the maximum specified in the
read() call. In the case of Progress it is BUFSIZ for buffered reads
or one character for INPUT FROM UNBUFFERED. If there is no data in
the FIFO queue to read, the reader will block on the read() system
call until a writer puts data in the queue. If the reader is blocked
waiting for data and the writer closes the named pipe, the read()
system call will return zero bytes read and an EOF status. At this
point, if the writer were to re-open the named pipe and write to it,
the reader could successfully retrieve the data by issuing another
read() system call.

Data written to the FIFO but not yet retrieved will remain in the
FIFO queue provided that the named pipe remains open by at least one
of the synchronized processes. If the named pipe is closed by all
readers and writers, any data not yet retrieved from the FIFO queue
will be lost. Subsequent synchronized opens of the named pipe will
start with an empty FIFO queue.

With this information as a backbround, you may wish to read the
companion knowledge base entry, Progress named pipe.

REFERENCE TO DOCUMENTATION
See unix man pages on your system. Some unix systems cover this in
section (2V).
pipe(2)
read(2)
write(2)

Progress Software Technical Support Note # 16373