UNIX is a time-sharing operating system. In addition to being a network operating system, it can also be used as a stand-alone operating system. UNIX, as a development platform and desktop operating system, has been widely used. At present, UNIX is mainly used in engineering applications, scientific computing and other fields.
Unix 是 20 世纪 70 年代初出现的一个操作系统，除了作为网络操作系统之外，还可以作为单机操作系统使用。Unix 作为一种开发平台和台式操作系统获得了广泛使用，目前主要用于工程应用和科学计算等领域。
UNIX is an operating system that appeared in the early 1970s. Besides being a network operating system, it can also be used as a stand-alone operating system. UNIX, as a development platform and desktop operating system, has been widely used. At present, UNIX is mainly used in engineering applications, scientific computing and other fields.
UNIX 系统是一个分时系统。最早的 UNIX 系统于 1970 年问世。此前，只有面向批处理作业的操作系统，这样的系统对于需要立即得到响应的用户来说是太慢了。在 60 年代末，Kenneth Thompson 和 Dennis Ritchie 都曾参加过交互方式分时系统 Multics 的设计，而开发该系统所使用的工具是 CTSS。这两个系统在操作系统的发展过程中都产生过重大影响。在此基础上，在对当时现有的技术进行精选提炼和发展的过程中，K.Thompson 于 1969 年在小型计算机上开发 UNIX 系统，后于 1970 年投入运行。
UNIX system is a time-sharing system. The first UNIX system came out in 1970. Previously, there were only operating systems for batch jobs, which were too slow for users who needed immediate response. In the late 1960s, both Kenneth Thompson and Dennis Ritchie participated in the design of interactive time-sharing system MULTICS, and CTSS was used to develop the system. These two systems have had a significant impact on the development of the operating system. On this basis, in the process of refining and developing the existing technology at that time, K. Thompson developed UNIX system on a small computer in 1969, and then put it into operation in 1970.
1973 年，DennisRitchie 开发出 C 语言，用来改写原来用汇编语言编写的 UNIX，由此产生了 UNIX VersionV。1974 年，Kenneth Thompson 和 Dennis Ritchie 合写的“The UNIX Time-Sharing System”在 Communication of ACM 上发表，正式向外界披露了 UNIX 系统。
In 1973, Dennis Ritchie developed c language, which was used to rewrite the original UNIX written in assembly language, resulting in UNIX version v. In 1974, Kenneth Thompson and Dennis Ritchie jointly wrote “the UNIX time sharing system” and published it on communication of ACM, officially disclosing the UNIX system to the outside world.
当时，PDP-11 系列小型计算机在世界各地已经得到广泛应用，UNIX 系统一开发后便广泛配备于美国各大学的 PDP-11 系列计算机上，由此为 UNIX 的广泛应用创造了物质条件。
At that time, PDP-11 series minicomputers had been widely used all over the world. As soon as UNIX system was developed, it was widely equipped on PDP-11 series computers in American universities, which created material conditions for the wide application of UNIX.
1978 年，UNIX Version VI 发表，随后又于 1979 年用于 VAX-11 超级小型机。以后，不断地出现各种新的版本。美国电话电报公司分别于 1981 年和 1983 年发表 AT&T UNIX SystemII 和 UNIX SystemV。美国加州大学伯克莱分校也先后发表了 UNIX 的版本 BSD4.1，BSD4.2 和 BSD4.3。
In 1978, UNIX version VI was published, and then used in VAX-11 supercomputer in 1979. Since then, there have been various new versions. At & T UNIX System II and UNIX System V were published by at & T in 1981 and 1983, respectively. The University of California, Berkeley, has also published versions of bsd4.1, bsd4.2 and bsd4.3 for UNIX.
现在 UNIX 系统的用户日益增多，应用范围也日益扩大。无论在各种类型的微型机、小型机，还是在中、大型计算机，以及在计算机工作站甚至个人计算机上，很多都已配有 UNIX 系统。不仅新推出的机型配有 UNIX 系统，而且一些历史较久的生产厂商，也竞相将原有机型配上 UNIX 系统以便打开销路、争取市场。
Nowadays, the users of UNIX system are increasing day by day, and the application scope is also expanding day by day. No matter in various types of microcomputers, minicomputers, medium and large computers, as well as in computer workstations and even personal computers, many have been equipped with UNIX systems. Not only the new model is equipped with UNIX system, but also some manufacturers with a long history are competing to match the original model with UNIX system in order to open the market and strive for the market.
UNIX 系统在计算机操作系统的发展史上占有重要的地位。它确实对已有技术不断作了精细、谨慎而有选择的继承和改造，并且，在操作系统的总体设计构想等方面有所发展，才使它获得如此大的成功。UNIX 系统的主要特点表现在以下几方面：
UNIX system plays an important role in the development history of computer operating system. It does inherit and transform the existing technology carefully, carefully and selectively, and develops the overall design concept of the operating system, which makes it so successful. The main characteristics of UNIX system are as follows:
(1) UNIX system is divided into two parts: kernel and shell, and the two parts are integrated into a whole. The core part is responsible for the functions of each module in the system, i.e. processor and process management, storage management, device management and file system. The characteristic of the core program is that it is designed meticulously, succinct and concise. It only needs to occupy a small space and stay in memory to ensure the high efficiency of the system. The peripheral part includes the user interface, system utility and application program of the system. The user uses the computer through the peripheral program.
(2)UNIX 系统提供了良好的用户界面，具有使用方便、功能齐全、清晰而灵活、易于扩充和修改等特点。UNIX 系统的使用有两种形式：一种是操作命令，即 shell 语言，是用户可以通过终端与系统发生交互作用的界面；另一种是面向用户程序的界面，它不仅在汇编语言，而且在 C 语言中向用户提供服务。
(2) UNIX system provides a good user interface, which is easy to use, full of functions, clear and flexible, easy to expand and modify. There are two forms of UNIX system use: one is the operation command, namely shell language, which is the interface that users can interact with the system through the terminal; the other is the user program oriented interface, which not only provides services to users in assembly language, but also in C language.
(3) The file system of UNIX system is a tree structure. It is composed of basic file system and thousands of detachable sub file systems, which can not only enlarge the storage space of files, but also be beneficial to security and confidentiality.
(4) UNIX system processes files, file directories and devices in a unified way. It takes files as character streams without any records for sequential or random access, and makes files, file directories and devices have the same syntax and semantics and the same protection mechanism, which not only simplifies the system design, but also facilitates the use of users.
(5) UNIX system contains a lot of language processing programs, utility programs and software development tools, which provides users with a fairly complete software development environment.
(6)UNIX 系统的绝大部分程序是用 C 语言编程的，只有约占 5%的程序用汇编语言编程。C 语言是一种高级程序设计语言，它使得 UNIX 系统易于理解、修改和扩充，并且具有非常好的移植性。
(6) Most programs of UNIX system are programmed in C language, only about 5% of them are programmed in assembly language. C language is a high-level programming language, which makes UNIX system easy to understand, modify and expand, and has a very good portability.
(7) UNIX system also provides simple communication between processes.
The operating system should manage the hardware and software resources of the computer system so that they can be used by users. Hardware resources generally refer to CPU (central processor), memory (memory and external memory), external devices, etc. Software resources refer to system programs and data, i.e. operating system, system utility programs and application software, as well as user programs and data, which are stored in memory in the form of files. The operating system is organically linked by several functional modules to work coordinately. These modules are: processor and process management module, storage management module, device management module, file system and user interface.
Processor and process management module
由于处理机(CPU)是计算机中关键的资源，进程的执行与 CPU 密切相关，因此处理机和进程管理模块可简称为进程管理模块。我们把确定哪些作业将调入内存运行和完成运行后撤出内存的工作称为作业调度。把如何控制一个作业在运行阶段的三个状态间的转换称为进程调度。因而，如何充分发挥资源的利用率，使响应时间短，使各用户作业等待执行的时间最短，是制订相应的作业调度算法和进程调度算法的原则。只是在不同的操作系统中，对以上目标有不同的着重点，因而调度算法也就有所不同。
Because the processor (CPU) is the key resource in the computer and the execution of the process is closely related to the CPU, the processor and the process management module can be referred to as the process management module for short. We call job scheduling the task of determining which jobs will be transferred into memory to run and which jobs will be withdrawn from memory after running. How to control the transition between three states of a job in the running phase is called process scheduling. Therefore, how to make full use of the resource utilization, make the response time short and make the waiting time of each user’s job the shortest is the principle of formulating the corresponding job scheduling algorithm and process scheduling algorithm. Only in different operating systems, there are different priorities for the above goals, so the scheduling algorithm is different.
Storage management module
存储管理是对作业从进入就绪状态起到运行结束之间所使用的存储器(包括内存和外存)进行管理。可以将存储管理模块的任务分为存储分配、地址映射和存储保护 3 部分。
Storage management is to manage the memory (including memory and external memory) used by the job from entering the ready state to the end of operation. The tasks of the storage management module can be divided into three parts: storage allocation, address mapping and storage protection.
一个程序在编译和链接后，得到一个称为内存映像的文件。该文件描述了这个程序在运行时所需要的内存大小，其中包括代码和数据区的地址。这些地址称为逻辑地址，并且以首地址 0 为参考地址。每当一个作业调入内存，进入就绪状态，存储管理模块就要根据可利用的内存空间与作业所需要的内存两者进行计算，给该作业分配相应的内存空间。
After a program compiles and links, it gets a file called memory image. This file describes the amount of memory the program needs to run, including the code and the address of the data area. These addresses are called logical addresses and are referenced by the first address 0. Whenever a job is transferred into memory and in ready state, the storage management module will calculate the available memory space and the memory required by the job, and allocate the corresponding memory space to the job.
Loading a job into memory means that a process will be created. The storage management module aligns the image file first address (zero) of the job with the first address of the process in memory. The first address or starting address of this process is the physical address in memory, which is called offset. The logical address of the image file plus the offset, the address values in the memory are all physical addresses. The translation of a logical address to a physical address is called address mapping. All logical addresses in the image can be converted to physical addresses.
Memory space is always shared by several processes, including the part of the operating system itself that needs to reside in memory. The task of memory protection is to know the divided areas in memory space, which processes they belong to, and which areas each process has access to. Whenever a process needs to access an address during execution, the storage management module should check whether the process has access to the physical address. Generally, the area in memory of each process is the legal address that the process can access. If the address of the access falls outside the region of the process, illegal access is generated. In case of illegal access, memory protection will deny access and handle errors.
1989 年下半年，C 程序设计语言的 ANSI 标准 X3.159-1989 得到批准。此标准被也采纳为国际标准 ISO/IEC9899:1990。ANSI 是美国国家标准学会(American National Standards Institute)的缩写，它是国际标准化组织(International Organization for Standardization，ISO)中代表美国的成 25]员。IEC 是国际电子技术委员会(International Electrotechnical Commission)的缩写。
In the second half of 1989, ANSI standard x3.159-1989 of C programming language was approved. This standard is also adopted as the international standard ISO / iec9899:1990. ANSI is the abbreviation of the American National Standards Institute. It is a member of the international organization for Standardization (ISO) representing the United States. IEC is the abbreviation of international electronic Commission.
ISO C 标准现在由 ISO/IEC 的 C 程序设计语言国际标准工作组维护和开发。ISO C 标准的意图是提供 C 程序的可移植性，使其能适合于大量不同的操作系统，而不只是适合 UNIX 系统。此标准不仅定义了 C 程序设计语言的语法和语义，还定义了其标准库。
ISO C standard is now maintained and developed by ISO / IEC’s C programming language international standards working group. The purpose of ISO C standard is to provide the portability of C program, making it suitable for a large number of different operating systems, not just UNIX systems. This standard not only defines the syntax and semantics of C programming language, but also defines its standard library.
1999 年，ISO C 标准被更新，并被批准为 ISO/IEC 9899:1999，它显著改善了对进行数值处理的应用软件的支持。除了对某些函数原型增加了关键字 restrict 外，这种改变并不影响本书中描述的 POSIX 接口。restrict 关键字告诉编译器，哪些指针引用是可以优化的，其方法是指出指针引用的对象在函数中只通过该指针进行访问。
In 1999, ISO C standard was updated and approved as ISO / IEC 9899:1999, which significantly improved the support of application software for numerical processing. In addition to adding the keyword restrict to some function prototypes, this change does not affect the POSIX interface described in this book. The restrict keyword tells the compiler which pointer references can be optimized by indicating that the object referenced by the pointer is only accessed through the pointer in the function.
1999 年以来，已经公布了 3 个技术勘误来修正 ISO C 标准中的错误，分别在 2001 年、2004 年和 2007 年公布。如同大多数标准一样，在批准标准和修改软件使其符合标准两者之间有一段时间延迟。随着供应商编译系统的不断演化，对最新 ISO C 标准的支持也就越来越多。
Since 1999, three technical corrigendums have been published to correct the errors in ISO C standards, respectively in 2001, 2004 and 2007. As with most standards, there is a delay between approving the standard and modifying the software to make it compliant. With the continuous evolution of the supplier’s compilation system, the support for the latest ISO C standard is increasing.
FreeBSD 是完全开放源代码的类 UNIX 系统，它的发展始于 1993 年，源于 386/BSD。FreeBSD 以易用性与高性能而著称。在最初的发行版中，FreeBSD 只支持 PC 硬件架构，后来又被移植到其他的硬件上面。
FreeBSD is a fully open source UNIX like system. Its development began in 1993 and originated from 386 / BSD. FreeBSD is known for its ease of use and high performance. In the initial release, FreeBSD only supported PC hardware architecture, and later was ported to other hardware.
NetBSD 同样也是一个完全开放源代码的类 UNIX 系统。最初 FreeBSD 只能运行在 PC 硬件上，为了 FreeBSD 能够兼容其他的硬件，便产生了一个 FreeBSD 的衍生版 NetBSD。可以说，NetBSD 就是为了提高 FreeBSD 的可移植性而产生的一个 BSD 发行版。
NetBSD is also a fully open source UNIX like system. At first, FreeBSD can only run on PC hardware. In order to make FreeBSD compatible with other hardware, a derivative version of FreeBSD, NetBSD, was produced. It can be said that NetBSD is a BSD distribution produced to improve the portability of FreeBSD.
OpenBSD 同样也是一个从 BSD 派生出的类 UNIX 操作系统。与 NetBSD 不同，OpenBSD 的关注点在于安全。著名的 Open SSH 协议就是最先在 OpenBSD 上实现的。OpenBSD 的吉祥物是一个名称为 Puffy 的河豚。
OpenBSD is also a UNIX like operating system derived from BSD. Unlike NetBSD, OpenBSD focuses on security. The famous open SSH protocol was first implemented on OpenBSD. OpenBSD’s mascot is a puffy puffer.
在 UNIX 的各发行版中，Open Solaris 是唯一个由商业版转为开放源代码的个
Of the UNIX distributions, open Solaris is the only one to move from commercial to open source