headers now go at top of page 1
[unix-history] / usr / src / share / doc / psd / 01.cacm / p1
CommitLineData
e85ca619 1.\" @(#)p1 6.2 (Berkeley) %G%
67d06d15 2.\"
e85ca619
KM
3.OH 'The UNIX Time-Sharing System''PS2:1-%'
4.EH 'PS2:1-%''The UNIX Time-Sharing System'
67d06d15
NC
5.ds n \s+2
6.hw above-mentioned
7.ds s \s-2
8.ds m \v'-.3'.\v'.3'
9.TL
10The UNIX
11Time-Sharing System\f1\s10\v'-.2n'*\v'.2n'\s0\fP
12.AU
13D. M. Ritchie and K. Thompson
14.AB
15.FS
16* Copyright 1974,
17Association for Computing Machinery, Inc.,
18reprinted by permission.
19This is a revised version of an article
20that appeared in Communications of the \*sACM\*n,
21.IT 17 ,
22No. 7 (July 1974), pp. 365-375.
23That article was a
24revised version of a paper presented
25at the Fourth \*sACM\*n Symposium on Operating
26Systems Principles,
27\*sIBM\*n Thomas J. Watson Research Center,
28Yorktown Heights,
29New York,
30October 15-17, 1973.
31.FE
32.UX
33is a general-purpose, multi-user, interactive
34operating system for the larger Digital Equipment Corporation
35\*sPDP\*n-11 and
36the Interdata 8/32 computers.
37It offers a number of features
38seldom found even in larger operating
39systems, including
40.IP i
41A hierarchical file system incorporating
42demountable volumes,
43.IP ii
44Compatible file, device, and inter-process I/O,
45.IP iii
46The ability to initiate asynchronous processes,
47.IP iv
48System command language selectable on a per-user basis,
49.IP v
50Over 100 subsystems including a dozen languages,
51.IP vi
52High degree of portability.
53.LP
54This paper discusses the nature
55and implementation of the file system
56and of the user command interface.
57.AE
58.NH
59INTRODUCTION
60.PP
61There have been four versions of
62the
63.UX
64time-sharing system.
65.hy 12
66The earliest (circa 1969-70) ran on
67the Digital Equipment Corporation \*sPDP\*n-7 and -9 computers.
68The second version ran on the unprotected
69\*sPDP\*n-11/20 computer.
70The third incorporated multiprogramming and ran
71on the \*sPDP\*n-11/34, /40, /45, /60, and /70 computers;
72it is the one described in the previously published version
73of this paper, and is also the most widely used today.
74.hy 14
75This paper describes only the
76fourth, current
77system that runs on the \*sPDP\*n-11/70 and the
78Interdata 8/32 computers.
79In fact, the differences among the various systems is
80rather small;
81most of the revisions made to the originally published version of this
82paper,
83aside from those concerned with style,
84had to do with details of the implementation of the file system.
85.PP
86Since
87\*sPDP\*n-11
88.UX
89became operational
90in February, 1971,
91over 600 installations have been put into service.
92Most of them are engaged in applications such as
93computer science education,
94the preparation and formatting of documents
95and other textual material,
96the collection and processing of trouble data
97from various switching machines within the Bell System,
98and recording and checking telephone service
99orders.
100Our own installation is used mainly for research
101in operating systems, languages,
102computer networks,
103and other topics in computer science, and also for
104document preparation.
105.PP
106Perhaps the most important achievement of
107.UX
108is to demonstrate
109that
110a powerful operating system for interactive use
111need not be expensive either in equipment or in human
112effort:
113it
114can run on hardware costing as little as $40,000, and
115less than two man-years were spent on the main system
116software.
117We hope, however, that users find
118that the
119most important characteristics of the system
120are its simplicity, elegance, and ease of use.
121.PP
122Besides the operating system proper, some major programs
123available under
124.UX
125are
126.DS
127.nf
128C compiler
129Text editor based on \*sQED\*n
130.[
131qed lampson
132.]
133Assembler, linking loader, symbolic debugger
134Phototypesetting and equation setting programs
135.[
136cherry kernighan typesetting mathematics cacm
137.]
138.[
139kernighan lesk ossanna document preparation bstj
140%Q This issue
141.]
142.fi
143.in +3n
144.ll -5n
145.ti -3n
146Dozens of languages including
147Fortran 77, Basic, Snobol, \*sAPL\*n, Algol 68, M6, \*sTMG\*n, Pascal
148.in
149.ll
150.DE
151There is a host of maintenance, utility, recreation and novelty programs,
152all written locally.
153The
154.UX
155user community, which numbers in the thousands,
156has contributed many more programs and languages.
157It is worth noting that the system is totally self-supporting.
158All
159.UX
160software is maintained on
161the
162system;
163likewise, this paper and all other
164documents
165in this issue
166were generated and formatted by the
167.UX
168editor and text formatting
169programs.
170.SH
171II. HARDWARE AND SOFTWARE ENVIRONMENT
172.PP
173The \*sPDP\*n-11/70 on which the Research
174.UX
175system is installed is a 16-bit
176word (8-bit byte) computer with 768K bytes of core memory;
177the system kernel
178occupies 90K bytes
179about equally divided between code
180and data tables.
181This system, however, includes a very large number of
182device drivers
183and enjoys a generous allotment
184of space for I/O buffers and system tables;
185a minimal system capable of running the software
186mentioned above can
187require as little as 96K bytes
188of core altogether.
189There are even larger installations;
190see the description of the
191\*sPWB/UNIX\*n systems,
192.[
193dolotta mashey workbench software engineering
194.]
195.[
196dolotta haight mashey workbench bstj
197%Q This issue
198.]
199for example.
200There are also much smaller, though somewhat restricted,
201versions of the system.
202.[
203lycklama microprocessor bstj
204%Q This issue
205.]
206.PP
207Our own \*sPDP\*n-11 has two
208200-Mb moving-head disks
209for file system storage and swapping.
210There are 20 variable-speed
211communications interfaces
212attached to 300- and 1200-baud data sets,
213and an additional 12 communication lines
214hard-wired to 9600-baud terminals and
215satellite computers.
216There are also several 2400- and 4800-baud
217synchronous communication interfaces
218used for machine-to-machine file transfer.
219Finally, there is a variety
220of miscellaneous
221devices including
222nine-track magnetic tape,
223a line printer,
224a voice synthesizer,
225a phototypesetter,
226a digital switching network,
227and a chess machine.
228.PP
229The preponderance of
230.UX
231software is written in the
232abovementioned C language.
233.[
234c programming language kernighan ritchie prentice-hall
235.]
236Early versions of the operating system were written in assembly language,
237but during the summer of 1973, it was rewritten in C.
238The size of the new system was about one-third greater
239than that of the old.
240Since the new system not only became much easier to
241understand and to modify but also
242included
243many functional improvements,
244including multiprogramming and the ability to
245share reentrant code among several user programs,
246we consider this increase in size quite acceptable.
247.SH
248III. THE FILE SYSTEM
249.PP
250The most important role of
251the system
252is to provide
253a file system.
254From the point of view of the user, there
255are three kinds of files: ordinary disk files,
256directories, and special files.
257.SH
2583.1 Ordinary files
259.PP
260A file
261contains whatever information the user places on it,
262for example, symbolic or binary
263(object) programs.
264No particular structuring is expected by the system.
265A file of text consists simply of a string
266of characters, with lines demarcated by the newline character.
267Binary programs are sequences of words as
268they will appear in core memory when the program
269starts executing.
270A few user programs manipulate files with more
271structure;
272for example, the assembler generates, and the loader
273expects, an object file in a particular format.
274However,
275the structure of files is controlled by
276the programs that use them, not by the system.
277.SH
2783.2 Directories
279.PP
280Directories provide
281the mapping between the names of files
282and the files themselves, and thus
283induce a structure on the file system as a whole.
284Each user has a directory of his own files;
285he may also create subdirectories to contain
286groups of files conveniently treated together.
287A directory behaves exactly like an ordinary file except that it
288cannot be written on by unprivileged programs, so that the system
289controls the contents of directories.
290However, anyone with
291appropriate permission may read a directory just like any other file.
292.PP
293The system maintains several directories
294for its own use.
295One of these is the
296.UL root
297directory.
298All files in the system can be found by tracing
299a path through a chain of directories
300until the desired file is reached.
301The starting point for such searches is often the
302.UL root .
303Other system directories contain all the programs provided
304for general use; that is, all the
305.IT commands .
306As will be seen, however, it is by no means necessary
307that a program reside in one of these directories for it
308to be executed.
309.PP
310Files are named by sequences of 14 or
311fewer characters.
312When the name of a file is specified to the
313system, it may be in the form of a
314.IT path
315.IT name ,
316which
317is a sequence of directory names separated by slashes, ``/\^'',
318and ending in a file name.
319If the sequence begins with a slash, the search begins in the
320root directory.
321The name
322.UL /alpha/beta/gamma
323causes the system to search
324the root for directory
325.UL alpha ,
326then to search
327.UL alpha
328for
329.UL beta ,
330finally to find
331.UL gamma
332in
333.UL beta .
334.UL \&gamma
335may be an ordinary file, a directory, or a special
336file.
337As a limiting case, the name ``/\^'' refers to the root itself.
338.PP
339A path name not starting with ``/\^'' causes the system to begin the
340search in the user's current directory.
341Thus, the name
342.UL alpha/beta
343specifies the file named
344.UL beta
345in
346subdirectory
347.UL alpha
348of the current
349directory.
350The simplest kind of name, for example,
351.UL alpha ,
352refers to a file that itself is found in the current
353directory.
354As another limiting case, the null file name refers
355to the current directory.
356.PP
357The same non-directory file may appear in several directories under
358possibly different names.
359This feature is called
360.IT linking ;
361a directory entry for a file is sometimes called a link.
362The
363.UX
364system
365differs from other systems in which linking is permitted
366in that all links to a file have equal status.
367That is, a file does not exist within a particular directory;
368the directory entry for a file consists merely
369of its name and a pointer to the information actually
370describing the file.
371Thus a file exists independently of any
372directory entry, although in practice a file is made to
373disappear along with the last link to it.
374.PP
375Each directory always has at least two entries.
376The name
377``\|\fB.\|\fP'' in each directory refers to the directory itself.
378Thus a program
379may read the current directory under the name ``\fB\|.\|\fP'' without knowing
380its complete path name.
381The name ``\fB\|.\|.\|\fP'' by convention refers to the parent of the
382directory in which it appears, that is, to the directory in which
383it was created.
384.PP
385The directory structure is constrained to have the form
386of a rooted tree.
387Except for the special entries ``\|\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP'', each directory
388must appear as an entry in exactly one other directory, which is its
389parent.
390The reason for this is to simplify the writing of programs
391that visit subtrees of the directory structure, and more
392important, to avoid the separation of portions of the hierarchy.
393If arbitrary links to directories were permitted, it would
394be quite difficult to detect when the last connection from
395the root to a directory was severed.
396.SH
3973.3 Special files
398.PP
399Special files constitute the most unusual feature of the
400.UX
401file system.
402Each supported I/O device
403is associated with at least one such file.
404Special files are read and written just like ordinary
405disk files, but requests to read or write result in activation of the associated
406device.
407An entry for each special file resides in directory
408.UL /dev ,
409although a link may be made to one of these files
410just as it may to an ordinary file.
411Thus, for example,
412to write on a magnetic tape
413one may write on the file
414.UL /dev/mt .
415Special files exist for each communication line, each disk,
416each tape drive,
417and for physical main memory.
418Of course,
419the active disks
420and the memory special file are protected from
421indiscriminate access.
422.PP
423There is a threefold advantage in treating
424I/O devices this way:
425file and device I/O
426are as similar as possible;
427file and device names have the same
428syntax and meaning, so that
429a program expecting a file name
430as a parameter can be passed a device
431name; finally,
432special files are subject to the same
433protection mechanism as regular files.
434.SH
4353.4 Removable file systems
436.PP
437Although the root of the file system is always stored on the same
438device,
439it is not necessary that the entire file system hierarchy
440reside on this device.
441There is a
442.UL mount
443system request with two arguments:
444the name of an existing ordinary file, and the name of a special
445file whose associated
446storage volume (e.g., a disk pack) should have the structure
447of an independent file system
448containing its own directory hierarchy.
449The effect of
450.UL mount
451is to cause
452references to the heretofore ordinary file
453to refer instead to the root directory
454of the file system on the removable volume.
455In effect,
456.UL mount
457replaces a leaf of the hierarchy tree (the ordinary file)
458by a whole new subtree (the hierarchy stored on the
459removable volume).
460After the
461.UL mount ,
462there is virtually no distinction
463between files on the removable volume and those in the
464permanent file system.
465In our installation, for example,
466the root directory resides
467on a small partition of one of
468our disk drives,
469while the other drive,
470which contains the user's files,
471is mounted by the system initialization
472sequence.
473A mountable file system is generated by
474writing on its corresponding special file.
475A utility program is available to create
476an empty file system,
477or one may simply copy an existing file system.
478.PP
479There is only one exception to the rule of identical
480treatment of files on different devices:
481no link may exist between one file system hierarchy and
482another.
483This restriction is enforced so as to avoid
484the elaborate bookkeeping
485that would otherwise be required to assure removal of the links
486whenever the removable volume is dismounted.
487.SH
4883.5 Protection
489.PP
490Although the access control scheme
491is quite simple, it has some unusual features.
492Each user of the system is assigned a unique
493user identification number.
494When a file is created, it is marked with
495the user \*sID\*n of its owner.
496Also given for new files
497is a set of ten protection bits.
498Nine of these specify
499independently read, write, and execute permission
500for the
501owner of the file,
502for other members of his group,
503and for all remaining users.
504.PP
505If the tenth bit is on, the system
506will temporarily change the user identification
507(hereafter, user \*sID\*n)
508of the current user to that of the creator of the file whenever
509the file is executed as a program.
510This change in user \*sID\*n is effective only
511during the execution of the program that calls for it.
512The set-user-\*sID\*n feature provides
513for privileged programs that may use files
514inaccessible to other users.
515For example, a program may keep an accounting file
516that should neither be read nor changed
517except by the program itself.
518If the set-user-\*sID\*n bit is on for the
519program, it may access the file although
520this access might be forbidden to other programs
521invoked by the given program's user.
522Since the actual user \*sID\*n
523of the invoker of any program
524is always available,
525set-user-\*sID\*n programs
526may take any measures desired to satisfy themselves
527as to their invoker's credentials.
528This mechanism is used to allow users to execute
529the carefully written
530commands
531that call privileged system entries.
532For example, there is a system entry
533invokable only by the ``super-user'' (below)
534that creates
535an empty directory.
536As indicated above, directories are expected to
537have entries for ``\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP''.
538The command which creates a directory
539is owned by the super-user
540and has the set-user-\*sID\*n bit set.
541After it checks its invoker's authorization to
542create the specified directory,
543it creates it and makes the entries
544for ``\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP''.
545.PP
546Because anyone may set the set-user-\*sID\*n
547bit on one of his own files,
548this mechanism is generally
549available without administrative intervention.
550For example,
551this protection scheme easily solves the \*sMOO\*n
552accounting problem posed by ``Aleph-null.''
553.[
554aleph null software practice
555.]
556.PP
557The system recognizes one particular user \*sID\*n (that of the ``super-user'') as
558exempt from the usual constraints on file access; thus (for example),
559programs may be written to dump and reload the file
560system without
561unwanted interference from the protection
562system.