Pipes

The Exec system call includes a pipectrl argument as defined in Process Management . This argument is used to direct the optional binding of OpenFileIds 0 (stdin) and 1 (stdout) to pipes rather than the console. This allows a process to create strings of child processes joined by a pipeline. A pipeline is a sequence of pipes, each with one reader and one writer. The first process in the pipeline has stdin bound to the console and stdout bound to the pipeline input. Processes in the middle of the pipeline have both stdin and stdout bound to pipes. The process at the end of the pipe writes its stdout to the console.

The Nachos interface for creating pipes is much simpler and less flexible than Unix. A parent process can use nonzero values of the pipectrl argument to direct that its children are to be strung out in a pipeline in the order in which they are created. A pipectrl value of 1 indicates that the process is the first process in the pipeline. A pipectrl value of 2 indicates a process in the middle of the pipeline; stdin is bound to the output of the preceding child, and stdout is bound to the input of the next child process to be created. A pipectrl value of 3 indicates that the process is at the end of the pipeline.

To handle these pipectrl values, the kernel must keep a list of all children of each process in the order that they are created.

Pipes are implemented as producer/consumer bounded buffers with a maximum buffer size of N bytes. If a process writes to a pipe that is full, the Write call blocks until the pipe has drained sufficiently to allow the write to continue. If a process reads from a pipe that is empty, the Read call blocks until the sending process exits or writes data into the pipe. If a process at either end of a pipe exits, the pipe is said to be broken : reads from a broken pipe drain the pipe and then stop returning data, and writes to a broken pipe silently discard the data written.