MULTICS TECHNICAL BULLETIN MTB763-03
To: MTB Distribution
From: G. William May
Date: July 9, 1987
Subject: Multics Command Level I/O redirection (pipes).
-----------------------------------
This MTB describes an addition to the Multics command line syntax
that will facilitate passing data between unrelated commands and
data storage devices via the standard I/O switches user_input and
user_output.
Rev 1: 06/15/87) Rewritten to include additional design
information. Rev 2: 06/23/87) Modified to show new pipe syntax.
Rev 3: 07/09/87) Revised Appendix B Manual Documentaton and
general cleanup.
-----------------------------------
Send comments by Multics mail to:
>udd>Multics>GWMay>mtgs>pipe_design_review.forum on System M
or
GWMay.Multics on System M
_________________________________________________________________
Multics project internal documentation; not to be reproduced or
distributed outside the Multics project without permission of the
Director of MDC.
- i -
MTB763-03 Multics Command Level Pipes
CONTENTS
Page
1: Introduction . . . . . . . . . . . . . . . . . . . . 1
2: Background Information . . . . . . . . . . . . . . . 2
3: Evaluation of the Uses of I/O Redirection . . . . . . 7
4: Proposal to Change Multics . . . . . . . . . . . . . 9
5: Detailed Proposal . . . . . . . . . . . . . . . . . . 10
5.1: Syntax . . . . . . . . . . . . . . . . . . . . . . 11
5.2: Usage . . . . . . . . . . . . . . . . . . . . . . . 13
5.3: Implementation . . . . . . . . . . . . . . . . . . 16
5.4: Placement of the I/O Redirection Facility . . . . . 18
5.5: Limitations . . . . . . . . . . . . . . . . . . . . 19
5.6: Impact to the Current System . . . . . . . . . . . 20
6: End Result . . . . . . . . . . . . . . . . . . . . . 21
7: MCR Decision Criteria Summary: . . . . . . . . . . . 22
8: Appendix A: Program Changes . . . . . . . . . . . . 24
9: Appendix B: Manual Documentation . . . . . . . . . . 31
- ii -
Multics Command Level Pipes MTB763-03
_1_: _I_N_T_R_O_D_U_C_T_I_O_N
One of the goals of the Multics organization for the MR12.1
release of the operating system is to make it possible to move
programs from other systems to Multics with little or no changes.
As part of the support for this effort, the design of the UNIX
system was reviewed. What we learned is that many of the
programs developed there rely on I/O redirection in order to move
data from one program to another. To see if these programs would
work on Multics, the capabilities for I/O redirection at command
level were evaluated. The evaluation showed that a need exists
for a simplified I/O redirection facility.
In an effort to make Multics available to a wider audience of
users and to make I/O redirection easier for our current users,
this project was requested to simplify Multics I/O redirection.
It is not the intent of this project to recreate any portion of
another operating system.
This design document includes:
1) background information on command level I/O redirection as it
exists in Multics today and as it is now being used in several
operating systems with large user communities.
2) an evaluation of the benefits of command level I/O redirection
to the Multics system as a whole.
3) a proposal for a change to the Multics system to add a
simplified method for redirecting I/O at command level.
4) a detailed proposal of the changes needed to implement
simplified command level I/O redirection.
5) detailed program and documentation changes.
- 1 -
MTB763-03 Multics Command Level Pipes
_2_: _B_A_C_K_G_R_O_U_N_D _I_N_F_O_R_M_A_T_I_O_N
Terminology
attach
the act of associating an I/O switch with a file, or other
I/O switch.
detach
the act of disassociating an I/O switch with a file, or
other I/O switch.
filter
commands that get input from standard input and put output
to standard output with each command modifying the input and
passing the data out through a standard path.
pipe
A logical stream of data created by redirecting the standard
input and output switches through a series of commands,
filters and I/O modules.
I/O module
a program that processes input and output requests directed
to a given switch. It may perform operations on other
switches, or call the supervisor.
I/O redirection
The act of changing the path in the I/O system through which
information is sent.
I/O switch
A path in the I/O system through which information is sent.
Multics I/O
A complete description of the current I/O facilities
available in the Multics environment is located in the
Multics Programmer's Reference Manual section 5. This MTB
assumes that the reader is familiar with the Multics I/O
system command io_call and the iox_ system subroutine.
- 2 -
Multics Command Level Pipes MTB763-03
I/O Redirection in Multics
To facilitate control of the sources and targets of I/O, the
Multics system makes use of a software construction called
an I/O switch. An I/O switch is like a channel in that it
controls the flow of data between program accessible storage
and devices, files, etc. The switch must be attached before
it can be used. The attachment specifies the source/target
for I/O operations and the particular I/O module that
performs the operations.
The ability to establish or change the path in the I/O
system through which information is sent is available at
command level, language I/O level and system I/O level. The
command level capabilities for I/O redirection are of
particular interest.
To redirect I/O at command level, the io_call and
file_output commands are used.
The user_output and error_output switches can be controlled
by use of the file_output, terminal_output and syn_output
commands. To feed the output of one command as input to
another, the following command sequence is used:
file_output file
command
revert_output
command2 ([contents file -nl]);
Any switch can be redirected by using the io_call command.
To redirect a switch like user_input, the following commands
are required:
io_call move_attach user_input save_user_input
io_call attach input_sw vfile_ some_file
io_call open input_sw stream_input
io_call attach user_input syn_ input_sw
command
io_call detach user_input
io_call close input_sw
io_call detach input_sw
io_call move_attach save_user_input user_input
UNIX I/O redirection
Several currently available operating systems use a concept
known as "pipes" to simplify I/O redirection. The concept
was developed for the UNIX operating environment and was
- 3 -
MTB763-03 Multics Command Level Pipes
designed as a command level simplification of the UNIX I/O
facilities which are modeled after the Multics I/O system.
To help readers of this document gain a general
understanding of pipes, the following section "UNIX pipes",
is taken from the text "The Design of the UNIX Operating
System" (Bach, 1986).
UNIX pipes
"The philosophy of the UNIX system is to provide operating
systems primitives that enable users to write small, modular
programs that can be used as building blocks to build more
complex programs. One such primitive visible to shell users
is the capability to redirect I/O. Processes conventionally
have access to three files: they read from their standard
input file, write to their standard output file, and write
error messages to their standard error file. Processes
executing at a terminal typically use these three files, but
each may be "redirected" independently. For instance, the
command line
ls
list all files in the current directory on the standard
output, but the command line
ls > output
redirects the standard output to the file called "output" in
the current directory, using the creat system call.
Similarly, the command line
mail mjb < letter
opens the file "letter" for its standard input and mails its
contents to the user named "mjb". Processes can redirect
input and output simultaneously, as in
nroff -mm < doc1 > doc1.out 2> errors
where the text formatter nroff reads the input file doc1,
redirects its standard output to the file doc1.out, and
redirects error messages to the file errors (the notation
"2>" means to redirect the output for file descriptor 2,
conventionally the standard error). the programs ls, mail,
and nroff do not know what file their standard input,
standard output, or standard error will be; the shell
recognizes the symbols "<", ">", and "2>" and sets up the
standard input, standard output, and standard error
appropriately before executing the processes.
- 4 -
Multics Command Level Pipes MTB763-03
The second building block primitive is the pipe, a mechanism
that allows a stream of data to be passed between reader and
writer processes. Processes can redirect their standard
output to a pipe to be read by other processes that have
redirected their standard input to come from the pipe. The
data that the first processes write into the pipe is the
input for the second processes. The second processes could
also redirect their output, and so on, depending on
programming need. Again, the processes need not know what
type of file their standard output is; they work regardless
of whether their standard output is a regular file, a pipe,
or a device. When using the smaller programs as building
blocks for a larger more complex program, the programmer
uses the pipe primitive and redirection of I/O to integrate
the piece parts. Indeed, the system tacitly encourages such
programming style so that new programs can work with
existing programs. For example, the program grep searches a
set of files (parameters to grep) for a given pattern:
grep main a.c b.c c.c
searches the three files a.c, b.c, and c.c for lines
containing the string "main" and prints the lines that it
finds onto standard output. Sample output may be:
a.c: main(argc, argv)
c.c:/* here is the main loop in the program */
c.c: main()
the program wc with the option -1 counts the number of lines
in the standard input file. The command line
grep main a.c b.c c.c|wc -1
counts the number of lines in the files that contain the
string "main"; the output from grep is "piped" directly into
the wc command. For the previous sample output from grep,
the output from the piped command is
3
The use of pipes frequently makes it unnecessary to create
temporary files."
Different Programming Philosophies
The concept of program modularity has always been one of the
many attractive features of the Multics system. It becomes
clear after reading the philosophy of the UNIX system above,
that there is a slight divergence between how the UNIX
community and Multics community view program modularity.
- 5 -
MTB763-03 Multics Command Level Pipes
Multics
The Multics view is that commands should be modularized by
function with each command providing a complete solution to
a set of requirements within the boundaries of the program.
The Multics command set provides control to its commands
through the use of control arguments. To complete the
model, commonly used system functions are provided by a
complete set of documented system subroutines. When it is
necessary to route the output of one command as input to
another, the active function capability or the file_output
command is used.
UNIX
The UNIX system follows much of the Multics design. A
documented subroutine library is available and commands do
accept Multics style control arguments. However, commands
are not organized to solve large sets of requirements or
offer generalized uses. Instead, UNIX commands are small
and very limited in functionality. As a result, they use
very few control arguments. The strength of the UNIX system
is realized when these small commands are combined to form
more powerful overall functions.
- 6 -
Multics Command Level Pipes MTB763-03
_3_: _E_V_A_L_U_A_T_I_O_N _O_F _T_H_E _U_S_E_S _O_F _I_/_O _R_E_D_I_R_E_C_T_I_O_N
Part of this design project is to determine whether the
Multics I/O redirection facilities are sufficient to support
the programs written on UNIX and UNIX-like systems. In
answer to this question, the Multics I/O system is flexible
and device independent. However, to redirect the flow of
I/O data is complex because the mechanisms are not hidden
from the user and the tools provided require a full
understanding of how to do I/O work.
For example to use the UNIX commands shown above on Multics,
the following commands would need to be given:
UNIX MULTICS
------------------+----------------------------------------------
ls > output ready_off
file_output output
ls
revert_output
ready_on
mail mjb < letter io_call move_attach user_input sv_user_input
io_call attach input_sw vfile_ letter
io_call open input_sw stream_input
io_call attach user_input syn_ input_sw
mail mjb
io_call detach user_input
io_call close input_sw
io_call detach input_sw
io_call move_attach sv_user_input user_input
nroff -mm < doc1 > doc1.out 2> errors
io_call move_attach user_input sv_user_input
io_call attach input_sw vfile_ doc1
io_call open input_sw stream_input
io_call attach user_input syn_ input_sw
ready_off
file_output doc1.out
file_output -isw error_output errors
nroff -mm
revert_output -isw error_output
ready_on
io_call detach user_input
io_call close input_sw
io_call detach input_sw
io_call move_attach sv_user_input user_input
It is clear that some improvement is needed to the I/O
redirection facilities if Multics plans to host commands
like those shown above. The next step is to decide what
- 7 -
MTB763-03 Multics Command Level Pipes
other benefits are possible from improved I/O redirection
facilities. Benefits to the Multics system and its users
include:
1) The ability to develop small single function filters on
the Multics system. By using the portable C compiler, it
is possible to move applications written as filters
directly to other computer systems.
2) It will be easy to redirect data through commands.
3) It will be possible to use existing Multics commands
which are not active functions as active functions.
For example, the output of the list command can be used
directly as input to a filter that uses entrynames.
4) New Multics commands may take advantage of the pipe
concept to improve the Multics environment by providing
broad based application of data across command
boundaries. This would be accomplished by creating
filters which perform the tasks currently provided by
control arguments in the Multics system.
For example, a command that outputs lines which match a
given string can be used in a pipe string. This single
filter could eliminate the need for duplication of a
-match control argument and supporting code in every
command that needs to match string data.
- 8 -
Multics Command Level Pipes MTB763-03
_4_: _P_R_O_P_O_S_A_L _T_O _C_H_A_N_G_E _M_U_L_T_I_C_S
Problem Description
The evaluation of the Multics system I/O redirection
facilities above indicates that it is not convenient to use
filter type commands on Multics.
To make it possible to move filter commands to Multics and
use them there, the I/O redirection facility needs to be
simplified.
Summary of Change
To simplify the Multics I/O redirection facility, the
functions of the current I/O commands that perform I/O
redirection will be hidden from users. The solution will
provide a shorthand method of performing I/O attach, open,
close and detach operations.
Design Constraints
The simplified I/O redirection interface must:
1) provide a simple useful syntax.
2) provide the ability to easily redirect the Multics
standard user_input and user_output I/O switches.
3) provide the ability to specify the I/O attach
descriptions for user_input and user_output.
4) make a minimal impact on the existing system.
5) interact with the existing system command level
facilities.
Expected Results
A simple interface that provides the ability to:
1) move filters to Multics and use them there.
2) move data directly from one file to another.
3) move data directly from one command to another.
4) move data directly from a file to a command and from a
command to a file.
- 9 -
MTB763-03 Multics Command Level Pipes
_5_: _D_E_T_A_I_L_E_D _P_R_O_P_O_S_A_L
In order to develop a simplified I/O redirection interface
the following steps were followed:
1) Design a simple useful syntax.
2) Develop the usage scenario for the syntax.
3) Develop the implementation for simplified I/O
redirection.
4) Determine the placement of simplified I/O redirection as
a facility within the Multics system.
5) Determine the impact to the system.
- 10 -
Multics Command Level Pipes MTB763-03
_5_._1_: _S_y_n_t_a_x
The following section details the development of the syntax
that will be used for the simplified I/O redirection
capability.
The UNIX Redirection Syntax
The syntax used by the UNIX system at command level to
facilitate I/O redirection as detailed above is: <, |, >
and 2> and on some systems ">>".
Part of the investigation for this project included
determining the importance of the syntax. Because the UNIX
syntax has been implemented on many UNIX-like machines, it
was a consideration to try to make the syntax available on
Multics.
The conflicts of implementing this syntax in Multics are:
1) The characters "<" and ">" are an integral part of the
Multics file system. They are reserved for delimiting
relative and absolute pathnames within the Multics
hierarchy.
2) The character "|" is used to delimit the base offset from
the word offset of a virtual pointer.
- 11 -
MTB763-03 Multics Command Level Pipes
The Multics Redirection Syntax
Because the characters "<", ">" and "|" have special meaning
at command level on the Multics system, the UNIX syntax
cannot be used.
Since a new syntax must be developed, it can be tailored for
use on the Multics system. By designing a pipe syntax
specifically for Multics, the full capabilities of the
system may be used to simplify and improve upon the UNIX
design.
The syntax proposed for denoting I/O redirection on the
Multics system is:
;|