1 Introduction
“UNIX” is the name of a time-sharing system for PDP11 computers, written by Ken Thompson and Dennis Ritchie at Bell Laboratories. It was described by them in the July, 1974 issue of the “Communications of the ACM”.
UNIX has proved to be effective, efficient and reliable in operation and was in use at more than 150 installations by the end of 1976.
The amount of effort to write UNIX, while not inconsiderable in itself (~10 man years up to the release of the Level Six system) is insignificant when compared to other systems. (For instance, by 1968, OS/360 was reputed to have consumed more then five man millennia and TSS/360, another IBM operating system, more than one man millennium.)
Of course there are systems which are easier to understand than UNIX but, it may be asserted, these are invariably much simpler and more modest in what they attempt to achieve. As far as the list of features offered to users is concerned, UNIX is in the “big league”. In fact it offers many features which are notable by their absence from some of the well-known major systems.
1.1 The UNIX Operating System
The purpose of this document, and its companion, the “UNIX Operating System Source Code”, is to present in detail that part of the UNIX time-sharing system which we choose to call the “UNIX Operating System”, namely the code which is permanently resident in the main memory during the operation of UNIX. This code has the following major functions:
initialisation;
process management;
system calls;
interrupt handling;
input/output operations;
file management.
1.2 Utilities
The remaining part of UNIX (which is much larger!) is composed of a set of suitably tailored programs which run as “user programs”, and which, for want of a better term, may be termed “utilities”.
Under this heading come a number of programs with a very strong symbiotic relationship with the operating system such as
the “shell” (the command language interpreter)
“/etc/init” (the terminal configuration controller)
and a number of file system management programs such as:
It should be pointed out that many of the functions carried out by the above-named programs are regarded as operating system functions in other computer systems, and that this certainly does contribute significantly to the bulk of these other systems as compared with the UNIX Operating System (in the way we have defined it).
Descriptions of the function and use of the above programs may be found in the “UNIX Programmer’s Manual” (UPM), either in Section I (for the commonly used programs) or in Section VIII (for the programs used only by the System Manager).
1.3 Other Documentation
These notes make frequent reference to the “UNIX Programmer’s Manual” (UPM), occasional reference to the “UNIX Documents” booklet, and constant reference to the “UNIX Operating System Source Code”.
All these are relevant to a complete understanding of the system. In addition, a full study of the assembly language routines requires reference to the “PDP11 Processor Handbook”, published by Digital Equipment Corporation.
1.4 UNIX Programmer’s Manual
The UPM is divided into eight major sections, preceded by a table of contents and a KWIC (Key Word In Context) index. The latter is mostly very useful but is occasionally annoying, as some indexed material does not exist, and some existing material is not indexed.
Within each section of the manual, the material is arranged alphabetically by subject name. The section number is conventionally appended to the subject name, since some subjects appear in more than one section, e.g. “CHDIR(I)” and “CHDIR(II)”.
- Section I
contains commands which either are recognised by the “shell” command interpreter, or are the names of standard user utility programs;
- Section II
contains “system calls” which are operating system routines which may be invoked from a user program to obtain operating system service. A study of the operating system will render most of these quite familiar;
- Section III
contains “subroutines” which are library routines which may be called from a user program. To the ordinary programmer, the distinctions between Sections II and III often appear somewhat arbitrary. Most of Section III is irrelevant to the operating system;
- Section IV
describes “special files”, which is another name for peripheral devices. Some of these are relevant, and some merely interesting. It depends where you are;
- Section V
describes “File Formats and Conventions”. A lot of highly relevant information is tucked away in this section;
- Sections VI and VII
describe “User Maintained” programs and subroutines. No UNIXophile will ignore these sections, but they are not particularly relevant to the operating system;
- Section VIII
describes “system maintenance” (software, not hardware!). There is lots of useful information here, especially if you are interested in how a UNIX installation is managed.
1.5 UNIX Documents
This is a somewhat miscellaneous collection of essays of varying degrees of relevance:
Setting up UNIX really belongs in Section VIII of the UPM (it’s relevant);
The UNIX Time-sharing System is an updated version of the original “Communications of the ACM” paper. It should be re-read at least once per month;
UNIX for Beginners is useful if your UNIX experience is limited;
The tutorials on “C” and the editor, and the reference manuals for “C” and the assembler are highly useful unless you are completely expert;
The UNIX I/O System provides a good overview of many features of the operating system;
UNIX Summary provides a check list which will be useful in answering the question what does an operating system do?
1.6 UNIX Operating System Source Code
This is an edited version of the operating system as supplied by Bell Laboratories.
The code selection presumes a “model” system consisting of:
PDP11/40 processor;
RK05 disk drives;
LP11 line printer;
PC11 paper tape reader/punch;
KL11 terminal interface.
The principal editorial changes to the source code are as follows:
the order of presentation of files has been changed;
the order of material within several files has been changed;
to a very limited extent, code has been transferred between files (with hindsight a lot more of this would have been desirable);
about 5% of the lines have been shortened in various ways to less than 66 characters (by elimination of blanks, rearrangement of comments, splitting into two lines, etc.);
a number of comments consisting of a line of underscore characters have been introduced, particularly at the end of procedures;
the size of each file has been adjusted to an exact multiple of 50 lines by padding with blank lines;
The source code has been printed in double column format with fifty lines per column, giving one hundred lines per sheet (or page). Thus there is a convenient relationship between line numbers and sheet numbers.
A number of summaries have been included at the beginning of the Source Code volume:
A Table of Contents showing files in order of appearance, together with the Procedures they contain;
An alphabetical list of procedures with line numbers;
A list of Defined Symbols with their values;
A Cross Reference Listing giving the line numbers where each symbol is used. (Reserved words in “C” and a number of commonly used symbols such as “p” and “u” have been omitted.)
1.7 Source Code Selections
The source code has been divided into five sections, each devoted primarily to a single major aspect of the system.
The intention, which has been largely achieved, has been to make each section sufficiently self-contained so that it may be studied as a unit and before its successors have been mastered:
- Section One
deals with system initialisation, and process management. It also contains all the assembly language routines;
- Section Two
deals with interrupts, traps, system calls and signals (software interrupts);
- Section Three
deals primarily with disk operations for program swapping and basic, block oriented input/output. It also deals with the manipulation of the pool of large buffers;
- Section Four
deals with files and file systems: their creation, maintenance, manipulation and destruction;
- Section Five
deals with “character special files”, which is the UNIX term for slow speed peripheral devices which operate out of a common, character oriented, buffer pool.
The contents of each section is outlined in more detail in Chapter Four.
1.8 Source Code Files
Each of the five sections just described consists of several source code files. The name of each file includes a suffix which identifies its type:
- “.s”
denotes a file of assembly language statements;
- “.c”
denotes a file of executable “C” language statements;
- “.h”
denotes a file of “C” language statements which is not for separate compilation, but for inclusion in other “.c” files when they are compiled i.e. the “.h” files contain global declarations.
1.9 Use of these notes
These notes, which are intended to supplement the comments already present in the source code, are not essential for understanding the UNIX operating system. It is perfectly possible to proceed without them, and you should attempt to do so as long as you can.
The notes are a crutch, to aid you when the going becomes difficult. If you attempt to read each file or procedure on your own first, your initial progress is likely to be slower, but your ultimate progress much faster. Reading other people’s programs is an art which should be learnt and practised because it is useful!
1.10 A Note on Programming Standards
You will find that most of the code in UNIX is of a very high standard. Many sections which initially seem complex and obscure, appear in the light of further investigation and reflection, to be perfectly obvious and “the only way to fly”.
For this reason, the occasional comments in the notes on programming style, almost invariably refer to apparent lapses from the usual standard of near perfection.
What caused these? Sometimes it appears that the original code has been patched expediently. More than once apparent lapses have proved not to be such: the “bad” code has been found in fact to incorporate some subtle feature which was not at all apparent initially. And some allowance is certainly needed for occasional human weakness.
But on the whole you will find that the authors of UNIX, Ken Thompson and Dennis Ritchie, have created a program of great strength, integrity and effectiveness, which you should admire and seek to emulate.