Information Technology Reference
In-Depth Information
write
read
Producer
Consumer
Pipe/Kernel Buffer
Figure3.6: A pipe is a temporary kernel data structure to connect a process
producing data with a process consuming the data.
of the pipe), as illustrated in Figure 3.6. Data is read in exactly the same
sequence it is written, but since the data is buffered, the execution of the
producer and consumer can be decoupled, reducing waiting in the common
case. The pipe terminates when either endpoint closes the pipe or exits.
The Internet has a similar facility to UNIX pipes called TCP (Transmis-
sion Control Protocol). Where UNIX pipes connect processes on the same
machine, TCP provides a bi-directional pipe between two processes run-
ning on different machines. In TCP, data is written as a sequence of bytes
on one machine, and read out as the same sequence on the other machine.
We plan to discuss the implementation of TCP in detail in a chapter to
be added to the next revision of this textbook.
Replace file descriptor. By manipulating the file descriptors of the
child process, the shell can cause the child to read its input from, or send
its output to, a file or a pipe instead of from a keyboard or to the screen.
This way, the child process does not need to be aware of who is providing or
consuming its I/O. The shell does this redirection using a special system
call named dup2(from,to) that replaces the to file descriptor with a
copy of the from file descriptor.
Wait for multiple reads. For client-server computing, a server may have
a pipe open to multiple client processes. Normally, read will block if there
is no data to be read, and it would be inecient for the server to poll each
pipe in turn to check if there is work for it to do. The UNIX system call
select(fd[],number) addresses this. Select allows the server to wait
for input from any of a set of file descriptors; it returns the file descriptor
that has data, but it does not read the data. Windows has an equivalent
function, called WaitForMultipleObjects .
Figure 3.7 summarizes the dozen UNIX system calls discussed in this section.
Search WWH ::




Custom Search