Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
Introduction unix

Introduction unix

Ratings: (0)|Views: 16 |Likes:
Published by ivaylo

More info:

Published by: ivaylo on May 11, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/29/2013

pdf

text

original

 
365
Electronic version recreated by Eric A. BrewerUniversity of California at BerkeleyCommunicationsJuly 1974ofVolume 17the ACMNumber 7
The UNIX Time-Sharing System
Dennis M. Ritchie and Ken ThompsonBell Laboratories
UNIX
is a general-purpose, multi-user, interactiveoperating system for the Digital Equipment Corpora-tion
PDP
-11/40 and 11/45 computers. It offers a numberof features seldom found even in larger operating sys-tems, including: (1) a hierarchical file system incorpo-rating demountable volumes; (2) compatible file, device,and inter-process
I
 / 
O
; (3) the ability to initiate asynchro-nous processes; (4) system command language select-able on a per-user basis; and (5) over 100 subsystemsincluding a dozen languages. This paper discusses thenature and implementation of the file system and of theuser command interface.Key Words and Phrases: time-sharing, operatingsystem, file system, command language,
PDP
-11CR Categories: 4.30, 4.32
Copyright
©
1974, Association for Computing Machinery,Inc. General permission to republish, but not for profit, all or partof this material is granted provided that ACM’s copyright notice isgiven and that reference is made to the publication, to its date of issue, and to the fact that reprinting privileges were granted bypermission of the Association for Computing Machinery.This is a revised version of a paper presented at the FourthACM Symposium on Operating Systems Principles, IBM ThomasJ. Watson Research Center, Yorktown Heights. New York, Octo-ber 15–17, 1973. Authors’ address: Bell Laboratories, MurrayHill, NJ 07974.The electronic version was recreated by Eric A. Brewer, Uni-versity of California at Berkeley, brewer@cs.berkeley.edu. Pleasenotify me of any deviations from the original; I have left errors inthe original unchanged.
1. Introduction
There have been three versions of 
UNIX
. The earliestversion (circa 1969–70) ran on the Digital Equipment Cor-poration
PDP
-7 and -9 computers. The second version ranon the unprotected
PDP
-11/20 computer. This paperdescribes only the
PDP
-11/40 and /45 [l] system since it ismore modern and many of the differences between it andolder
UNIX
systems result from redesign of features foundto be deficient or lacking.Since
PDP
-11
UNIX
became operational in February1971, about 40 installations have been put into service; theyare generally smaller than the system described here. Mostof them are engaged in applications such as the preparationand formatting of patent applications and other textualmaterial, the collection and processing of trouble data fromvarious switching machines within the Bell System, andrecording and checking telephone service orders. Our owninstallation is used mainly for research in operating sys-tems, languages, computer networks, and other topics incomputer science, and also for document preparation.Perhaps the most important achievement of 
UNIX
is todemonstrate that a powerful operating system for interac-tive use need not be expensive either in equipment or inhuman effort:
UNIX
can run on hardware costing as little as$40,000, and less than two man years were spent on themain system software. Yet
UNIX
contains a number of fea-tures seldom offered even in much larger systems. It ishoped, however, the users of 
UNIX
will find that the mostimportant characteristics of the system are its simplicity,elegance, and ease of use.Besides the system proper, the major programs avail-able under
UNIX
are: assembler, text editor based on
QED
[2], linking loader, symbolic debugger, compiler for a lan-guage resembling
BCPL
[3] with types and structures (C),interpreter for a dialect of 
BASIC
, text formatting program,Fortran compiler, Snobol interpreter, top-down compiler-compiler (
TMG
) [4], bottom-up compiler-compiler (
YACC
),form letter generator, macro processor (M6) [5], and per-muted index program.There is also a host of maintenance, utility, recreation,and novelty programs. All of these programs were writtenlocally. It is worth noting that the system is totally self-sup-porting. All
UNIX
software is maintained under
UNIX
; like-wise,
UNIX
documents are generated and formatted by the
UNIX
editor and text formatting program.
2. Hardware and Software Environment
The
PDP
-11/45 on which our
UNIX
installation is imple-mented is a 16-bit word (8-bit byte) computer with 144Kbytes of core memory;
UNIX
occupies 42K bytes. This sys-tem, however, includes a very large number of device driv-ers and enjoys a generous allotment of space for
I
 / 
O
buffersand system tables; a minimal system capable of running the
 
366
Electronic version recreated by Eric A. BrewerUniversity of California at BerkeleyCommunicationsJuly 1974ofVolume 17the ACMNumber 7
software mentioned above can require as little as 50K bytesof core altogether.The
PDP
-11 has a 1M byte fixed-head disk, used for filesystem storage and swapping, four moving-head disk driveswhich each provide 2.5M bytes on removable disk car-tridges, and a single moving-head disk drive which usesremovable 40M byte disk packs. There are also a high-speed paper tape reader-punch, nine-track magnetic tape,and D-tape (a variety of magnetic tape facility in whichindividual records may be addressed and rewritten).Besides the console typewriter, there are 14 variable-speedcommunications interfaces attached to 100-series datasetsand a 201 dataset interface used primarily for spoolingprintout to a communal line printer. There are also severalone-of-a-kind devices including a Picturephone
®
interface,a voice response unit, a voice synthesizer, a phototypesetter,a digital switching network, and a satellite
PDP
-11/20 whichgenerates vectors, curves, and characters on a Tektronix 611storage-tube display.The greater part of 
UNIX
software is written in theabove-mentioned C language [6]. Early versions of theoperating system were written in assembly language, butduring the summer of 1973, it was rewritten in C. The sizeof the new system is about one third greater than the old.Since the new system is not only much easier to understandand to modify but also includes many functional improve-ments, including multiprogramming and the ability to sharereentrant code among several user programs, we consideredthis increase in size quite acceptable.
3. The File System
The most important job of 
UNIX
is to provide a file sys-tem. From the point of view of the user, there are threekinds of files: ordinary disk files, directories, and specialfiles.
3.1 Ordinary Files
A file contains whatever information the user places onit, for example symbolic or binary (object) programs. Noparticular structuring is expected by the system. Files of text consist simply of a string of characters, with linesdemarcated by the new-line character. Binary programs aresequences of words as they will appear in core memorywhen the program starts executing. A few user programsmanipulate files with more structure: the assembler gener-ates and the loader expects an object file in a particular for-mat. However, the structure of files is controlled by theprograms which use them, not by the system.
3.2 Directories
Directories provide the mapping between the names of files and the files themselves, and thus induce a structure onthe file system as a whole. Each user has a directory of hisown files; he may also create subdirectories to containgroups of files conveniently treated together. A directorybehaves exactly like an ordinary file except that it cannot bewritten on by unprivileged programs, so that the systemcontrols the contents of directories. However, anyone withappropriate permission may read a directory just like anyother file.The system maintains several directories for its ownuse. One of these is the
root 
directory. All files in the sys-tem can be found by tracing a path through a chain of direc-tories until the desired file is reached. The starting point forsuch searches is often the root. Another system directorycontains all the programs provided for general use; that is,all the
commands
. As will be seen however, it is by nomeans necessary that a program reside in this directory forit to be executed.Files are named by sequences of 14 or fewer charac-ters. When the name of a file is specified to the system, itmay be in the form of a
 path name
, which is a sequence of directory names separated by slashes “/” and ending in afile name. If the sequence begins with a slash, the searchbegins in the root directory. The name / 
alpha
 / 
beta
 / 
gamma
causes the system to search the root for directory
alpha
,then to search
alpha
for
beta
, finally to find
gamma
in
beta
.
Gamma
may be an ordinary file, a directory, or a specialfile. As a limiting case, the name “/” refers to the root itself.A path name not starting with “/” causes the system tobegin the search in the user’s current directory. Thus, thename
alpha
 / 
beta
specifies the file named
beta
in subdirec-tory
alpha
of the current directory. The simplest kind of name, for example
alpha
, refers to a file which itself isfound in the current directory. As another limiting case, thenull file name refers to the current directory.The same nondirectory file may appear in severaldirectories under possibly different names. This feature iscalled
linking
; a directory entry for a file is sometimescalled a link.
UNIX
differs from other systems in which link-ing is permitted in that all links to a file have equal status.That is, a file does not exist within a particular directory;the directory entry for a file consists merely of its name anda pointer to the information actually describing the file.Thus a file exists independently of any directory entry,although in practice a file is made to disappear along withthe last link to it.Each directory always has at least two entries. Thename in each directory refers to the directory itself. Thus aprogram may read the current directory under the name “.”without knowing its complete path name. The name “..” byconvention refers to the parent of the directory in which itappears, that is, to the directory in which it was created.The directory structure is constrained to have the formof a rooted tree. Except for the special entries “.” and “..”,each directory must appear as an entry in exactly one other,which is its parent. The reason for this is to simplify thewriting of programs which visit subtrees of the directory
 
367
Electronic version recreated by Eric A. BrewerUniversity of California at BerkeleyCommunicationsJuly 1974ofVolume 17the ACMNumber 7
structure, and more important, to avoid the separation of portions of the hierarchy. If arbitrary links to directorieswere permitted, it would be quite difficult to detect whenthe last connection from the root to a directory was severed.
3.3 Special Files
Special files constitute the most unusual feature of the
UNIX
file system. Each
I
 / 
O
device supported by
UNIX
isassociated with at least one such file. Special files are readand written just like ordinary disk files, but requests to reador write result in activation of the associated device. Anentry for each special file resides in directory / 
dev
, althougha link may be made to one of these files just like an ordi-nary file. Thus, for example, to punch paper tape, one maywrite on the file / 
dev
 / 
 ppt 
. Special files exist for each com-munication line, each disk, each tape drive, and for physicalcore memory. Of course, the active disks and the core spe-cial file are protected from indiscriminate access.There is a threefold advantage in treating
I
 / 
O
devicesthis way: file and device
I
 / 
O
are as similar as possible; fileand device names have the same syntax and meaning, sothat a program expecting a file name as a parameter can bepassed a device name; finally, special files are subject to thesame protection mechanism as regular files.
3.4 Removable File Systems
Although the root of the file system is always stored onthe same device, it is not necessary that the entire file sys-tem hierarchy reside on this device. There is a
mount 
sys-tem request which has two arguments: the name of anexisting ordinary file, and the name of a direct-access spe-cial file whose associated storage volume (e.g. disk pack)should have the structure of an independent file system con-taining its own directory hierarchy. The effect of 
mount 
is tocause references to the heretofore ordinary file to referinstead to the root directory of the file system on the remov-able volume. In effect,
mount 
replaces a leaf of the hierar-chy tree (the ordinary file) by a whole new subtree (thehierarchy stored on the removable volume). After the
mount 
, there is virtually no distinction between files on theremovable volume and those in the permanent file system.In our installation, for example, the root directory resideson the fixed-head disk, and the large disk drive, which con-tains user’s files, is mounted by the system initializationprogram, the four smaller disk drives are available to usersfor mounting their own disk packs. A mountable file systemis generated by writing on its corresponding special file. Autility program is available to create an empty file system,or one may simply copy an existing file system.There is only one exception to the rule of identicaltreatment of files on different devices: no link may existbetween one file system hierarchy and another. This restric-tion is enforced so as to avoid the elaborate bookkeepingwhich would otherwise be required to assure removal of thelinks when the removable volume is finally dismounted. Inparticular, in the root directories of all file systems, remov-able or not, the name “..” refers to the directory itself instead of to its parent.
3.5 Protection
Although the access control scheme in
UNIX
is quitesimple, it has some unusual features. Each user of the sys-tem is assigned a unique user identification number. Whena file is created, it is marked with the user
ID
of its owner.Also given for new files is a set of seven protection bits. Sixof these specify independently read, write, and execute per-mission for the owner of the file and for all other users.If the seventh bit is on, the system will temporarilychange the user identification of the current user to that of the creator of the file whenever the file is executed as a pro-gram. This change in user
ID
is effective only during theexecution of the program which calls for it. The set-user-
ID
feature provides for privileged programs which may usefiles inaccessible to other users. For example, a programmay keep an accounting file which should neither be readnor changed except by the program itself. If the set-user-identification bit is on for the program, it may access thefile although this access might be forbidden to other pro-grams invoked by the given program’s user. Since theactual user
ID
of the invoker of any program is alwaysavailable, set-user-
ID
programs may take any measuresdesired to satisfy themselves as to their invoker’s creden-tials. This mechanism is used to allow users to execute thecarefully written commands which call privileged systementries. For example, there is a system entry invocable onlyby the “super-user” (below) which creates an empty direc-tory. As indicated above, directories are expected to haveentries for “.” and “..”. The command which creates a direc-tory is owned by the super user and has the set-user-
ID
bitset. After it checks its invoker’s authorization to create thespecified directory, it creates it and makes the entries for “.”and “..”.Since anyone may set the set-user-
ID
bit on one of hisown files, this mechanism is generally available with- outadministrative intervention. For example, this protectionscheme easily solves the
MOO
accounting problem posed in[7].The system recognizes one particular user
ID
(that of the “super-user”) as exempt from the usual constraints onfile access; thus (for example) programs may be written todump and reload the file system without unwanted interfer-ence from the protection system.
3.6
I
 / 
O
Calls
The system calls to do
I
 / 
O
are designed to eliminate thedifferences between the various devices and styles of access. There is no distinction between “random” andsequential
I
 / 
O
, nor is any logical record size imposed by thesystem. The size of an ordinary file is determined by the

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->