UNIX Operating System UNIX — Introductory Notes

Chapter 1: UNIX — Introductory Notes

1.1 UNIX Operating System

UNIX is a popular time−sharing operating system originally intended for program development and document preparation, but later widely accepted for a number of implementations. UNIX is todays most ubiquitous multi−user operating system, with no indication of any diminishment in the near future. Today, when a period of several years represents the lifetime of many successful IT products, UNIX is still considered the most stable and the most secure operating system on the market, three decades after its appearance. Of course, during 30 years of existence UNIX has changed a great deal, adapting to new requirements; it is hard to compare todays modern UNIX flavors with initial now obsolete UNIX versions. In fact, these changes and adaptations are unique to the UNIX operating system; no other operating system has so successfully evolved, time and again, to meet modern needs. The concept and basic design of UNIX deserve the credit for this remarkable longevity, as they provide the necessary flexibility for the permanent changes required to make UNIX suitable for many new applications. UNIX, like any other operating system, is an integrated collection of programs that act as links between the computer system and its users, providing three primary functions: Creating and managing a filesystem sets of files stored in hierarchical−structured directories 1. Running programs 2. Using system devices attached to the computer 3. UNIX was written in the C computer language, with careful isolation and confinement of machine−dependent routines, so that it might be easily ported to different computer systems. As a result, versions of UNIX were available for personal computers, workstations, minicomputers, mainframes, and supercomputers. It is somewhat curious to note that portability was not a design objective during UNIX development; rather, it came as a consequence of coding the system in a higher−level language. Upon realizing the importance of portability, the designers of UNIX confined hardware−dependent code to a few modules within the kernel coded in assembler in order to facilitate porting. The kernel is the core of the UNIX operating system. It provides services such as a filesystem, memory management, CPU scheduling, and device IO for programs. Typically, the kernel interacts directly with the underlying hardware; therefore, it must be adapted to the unique machine architecture. However, there were some implementations of UNIX in which the kernel interacted with another underlying system that in turn controlled the hardware. The kernel keeps track of who is logged in, as well as the locations of all files; it also accepts and enables instruction executions received from the shell as the output of interpreted commands. The kernel provides a limited number typically between 60 and 200 of direct entry points through which an active process can obtain services from the kernel. These direct entry points are system calls also known as UNIX internals. The actual machine instructions required to invoke a system call, along with the method used to pass arguments and results between the process and the kernel, vary from machine to machine. The machine−dependent parts of the kernel were cleverly isolated from the main kernel code and were relatively easy to construct once their purpose had been defined. The machine−dependent parts of the kernel include: 7 Fault, trap, interrupt, and exception handling • Memory management: hardware address translation • Low−level kerneluser mode process context switching • IO device drivers and device initialization code • The rest of the UNIX kernel is extremely transportable and is largely made up of the system call interface from which application programs request services. An early implementation of the UNIX kernel consisted of some 10,000 lines of C code and approximately 1000 lines of assembler code. These figures represent some 5 to 10 of the total UNIX code. When the original assembler version was recoded in C, the size and execution time of the kernel increased by some 30. UNIX designers reasoned that the benefits of coding the system in a higher−level language far outweighed the resulting performance drawback. These benefits included portability, higher programmer productivity, ease of maintenance, and the ability to use complex algorithms to provide more sophisticated functions. Some of these algorithms could hardly have been contemplated if they were to be coded in assembly language. UNIX supports multiple users on suitable installations with efficient memory−management and the appropriate communication interfaces. In addition to local users, log−in access and file transfer between UNIX hosts are also granted to remote users in the network environment. Virtually all aspects of device independence were implemented in UNIX. Files and IO devices are treated in a uniform way, by means of the same set of applicable system calls. As a result, IO redirection and stream−level IO are fully supported at both the command−language and system−call levels. The basic UNIX philosophy, to process and treat different requests and objects in a uniform and relatively simple way, is probably the key to its long life. In a fast−changing environment in which high−tech products become obsolete after a few years, UNIX is still in full operational stage, three decades after its introduction. UNIX owes much of its longevity to its integration of useful building blocks that are combinable according to current needs and preferences for the creation of more complex tools. These basic UNIX blocks are usually simple, and they are designed to accomplish a single function well. Numerous UNIX utilities, called filters, can be combined in remarkably flexible ways by using the facilities provided by IO redirection and pipes. This simple, building−block approach is obviously more convenient than the alternative of providing complex utilities that are often difficult to customize, and that are frequently incompatible with other utilities. UNIXs hierarchical filesystem helps facilitate the sharing and cooperation among users that is so desirable in program−development environment. A UNIX filesystem or filesystem, as it has become known spans volume boundaries, virtually eliminating the need for volume awareness among its users. This is especially convenient in time−sharing systems and in a network environment. The major features of UNIX can be summarized as: Portability • Multi−user operation • Device independence • Tools and tool−building utilities • Hierarchical filesystem • 8 UNIX users interact with the system through a command−language interpreter called the shell. A shell is actually what the user sees of the system; the rest of the operating system is essentially hidden from the users eyes. A UNIX shell or shells, because there are different command−interpreters is also a programming language suitable for the construction of versatile and powerful command files called shell scripts. The UNIX shell is written in the same way as any user process, as opposed to being built into the kernel. When a user logs into the system, a copy of the corresponding shell is invoked to handle interactions with the related user. Although the shell is the standard system interface, it is possible to invoke any user−specific process to serve in place of the shell for any specific user. This allows application−specific interfaces to coexist with the shell, and thus provide quite different views and working environments for users of the same system. All programs invoked within the shell start out with three predefined files, specified by corresponding file descriptors. By default the three files are: Standard input — normally assigned to the terminal console keyboard 1. Standard output — normally assigned to the terminal console display 2. Error output — normally assigned to the terminal console display 3. The shell fully supports: Redirection — Since IO devices and files are treated the same way in UNIX, the shell treats the two notions as files. From the users viewpoint, it is easy to redefine file descriptors for any program, and in that way replace attached standard input and output files; this is known as redirection. • Pipes — The standard output of one program can be used as standard input in another program by means of pipes. Several programs can be connected via pipes to form a pipeline. Redirection and piping are used to make UNIX utilities called filters, which are used to perform complex compound functions. • Concurrent execution of the user programs — Users may indicate their intention to invoke several programs concurrently by placing their execution in the background as opposed to the single foreground program that requires full control of the display. This mode of operation allows users to perform unrelated work while potentially lengthy operations are being performed in the background on their behalf. • Since UNIX was primarily intended for program development, it offers several editors, compilers, symbolic debuggers, and utilities. Other useful program development facilities of UNIX include a general−purpose macro−processor, M4, that is language−independent, and the MAKE program, which controls creation of other large programs. MAKE uses a control file or description file called MAKEFILE, which specifies source file dependencies among the constituent modules of a program. It identifies modules that are possibly out of date by checking the last program update, recompiles them, and links them into a new executable program. A much more elaborate system for large programming projects, called Source Code Control System — SCCS, is also available under UNIX. Although SCCS was designed to assist production of complex programs, it can also be used to manage any collection of text files. SCCS basically functions as a well−managed library of major and minor revisions of program modules. It keeps track of all changes, the identity of the programmers, and other information. It provides utilities for rolling back to any previous version, displaying complete or partial history of the changes made to a module, validation of modules, and the like. A complex implementation of SCCS evolved into a simpler version named Revision Control System — RCS, which is more suitable to manage text 9 Users generally have restricted access to the UNIX filesystem; however, they are fully authorized in their home directories, where they can create their own subdirectories and files. This restricted−access approach is necessary to protect the system from intended and unintended corruption, while still allowing users to have full control over their own programs. Filesystem protection in UNIX is accomplished by assigning ownership for each file and directory that is created. At creation, the access modes for the three access classes user−owner, group−owner, and others are also specified. Within each access class, three separate permissions are specified: for reading, writing, and execution of the file. Since everything in UNIX is a file or is file−like, this simple protection scheme is widely implemented throughout the whole operating system, making UNIX security and protection very efficient. Finally, UNIX is extremely well suited for networking. One of the reasons for UNIXs enormous popularity and wide implementation lies in its inherent network−related characteristics. UNIX facilitates most network functions in such a way that it can appear the network has been designed expressly for the UNIX architecture. The truth is that UNIX and modern networks have been developed independently, with UNIX preceding modern network architecture by a decade. The reason UNIX handles networking so well is simple: UNIXs flexible internal organization and structure allow an almost perfect union between the UNIX and network environments.

1.3 The History of UNIX