Unix yes 20 century 70 An operating system that emerged in the early s , In addition to being a network operating system , It can also be used as a stand-alone operating system . Now? Unix The number of users of the system is increasing , The scope of application is also expanding .Unix System plays an important role in the development history of computer operating system , The existing technology has been continuously refined , Prudent and selective inheritance and transformation , also , It has developed in the overall design concept of the operating system , To make it so successful . This article on Unix Principle of operating system , The advantages and disadvantages are briefly analyzed .
Unix System plays an important role in the development history of computer operating system , It is of great significance for us to learn embedded operating system . This paper mainly analyzes Unix Principle of operating system , merits and demerits . The principle part includes Unix Basic structure of the system ,Unix file system ,Unix Storage management .
<> one . Unix Principle of operating system
Unix Is a multi-user , Multitasking management operating system .Unix The system consists of hardware , kernel ,Shell And application composition , User through Shell Send user commands to the kernel .Unix The file system adopts tree structure .Unix Supports multiple processor architectures , Classification by operating system , It belongs to time-sharing operating system . Apple's system is based on Unix of .
<>1.Unix Basic structure of the system
（1） Kernel layer
Unix The function of system kernel is to interact with hardware and control hardware to provide abstract services to user programs . Responsible for resource management and process scheduling allocation in computer system , This includes interrupt handling , Memory management , Process management and I/O Document management, etc . These functions are provided by Unix Implementation of each module in the kernel . It includes modules that directly control the hardware .Unix The kernel is the first extension of computer hardware , Provide users with interfaces for services , Users cannot directly access the kernel .
（2）Shell And special program layer
Shell yes Unix User interface for , yes Unix An important part of the system . It is responsible for the interpretation and execution of user commands , complete Unix Setting of system user's working environment, etc , But it's not part of the kernel . stay Unix In the system , Some commands are implemented through the command interface of the application . The compilation part is also in Shell And special program layer .
（3） User program layer
User program layer Shell And external of special programs , The outermost layer with the compiler is the user's actual application . The compiler mainly compiles the user program into a form that can be recognized and processed by the system , Also at the user program level .
<>2.Unix file system
Unix The file system adopts tree file structure , Combination of inner core and outer core , The management mechanism and use method of equipment and file are the same .Unix File system pass “ Disk index i node ” and “ Catalog entry ” To manage , After the file is opened or referenced “ Memory index i node ”,“ User file description table ”,“ file table ”.
The file system is roughly divided into the following three areas in the disk ：
（1） Super block
The function is to store the structure information of the file system itself , For example, the size of each area and what free disk block information is available . The global file information is saved in the super block , If the hard disk has used space , Block free space ,i Node information, etc .
（2）i- Node table
Storage file properties , Size, owner, etc . each i- The size of the node structure is consistent , And the access method is similar to array , For example, to visit i- Node number is 9 of i- Node structure , Corresponding i- The second node in the node table 10 Location .i Node is Unix The core of files in the operating system , It is also the intermediary between the operating system and the data stored in the hard disk , If the node information is wrong , Then the data blocks stored in the hard disk will not be used by the user .
（3） Data area
The contents of the file are saved in this area , All blocks on the disk are the same size , If the contents of the file are stored, more than one block is required , Then use multiple blocks for storage . If the file is large , You need many disk blocks to store it .
<>3.Unix Storage management
Storage management is to manage the storage used by jobs from entering the ready state to the end of operation . Storage management module tasks can be divided into storage assignments , Address mapping and storage protection .
（1） Storage allocation
After compiling and linking a program , Get a file called a memory image . This file describes the amount of memory required for the program to run , This includes the address of the code and data area . These addresses are called logical addresses , And first address 0 Is the reference address . Whenever a job is called into memory , Enter ready state , The storage management module should calculate according to both the available memory space and the memory required by the job , Allocate the corresponding memory space to the job .
（2） Address mapping
Load a job into memory , Means that a process will be created . The storage management module will the first address of the image file of the job ( Zero ) Align the first address of the process in memory . The first or starting address of this process is the physical address in memory , Called offset . The logical address of the image file plus the offset , The address values obtained in memory are physical addresses . Calculating the conversion from logical address to physical address is called address mapping . All logical addresses in the image can be converted to physical addresses .
（3） Storage protection
Memory space is always shared by several processes , This includes the part of the operating system itself that needs to reside in memory . The task of memory protection is to protect the divided areas in the memory space , Know which processes they belong to , And know the areas that each process has access to . Whenever a process needs to access an address during execution , The storage management module checks whether the process has access to the physical address . usually , The area in memory of each process is the legal address that the process can access . If the accessed address falls outside the region of the process , That is, illegal access is generated . In case of illegal access , Memory protection is to deny access , And handle errors .
<> two . Unix Advantages of operating system
Unix System is one of the earliest operating systems , Now? Unix The technology of the system has become mature , It has the following advantages ：
<>1. High reliability
Unix The operating system has high reliability ,Unix Hosts and servers can remain 24 24-hour uninterrupted operation , use Unix Host of the system / The server is more stable and reliable . current Unix Operating system adopts 64 Bit technology , multiple I/O Improve system reliability and performance , Support controller hot plug , Hard disk bridging and mirroring, etc , It meets the complex application requirements .
<>2. Good user interface
Unix The system provides a good user interface , The utility model has the advantages of convenient use , Fully functional , Clear and flexible , Easy to expand and modify .Unix The system can be used in two forms ： One is operation command , Namely Shell language , It is an interface that users can interact with the system through the terminal ; The other is user program oriented interface , It's not just in assembly language , And in C Provide services to users in language . also Unix have 3 A mainstream Shell, At the same time, it provides users with thousands of system commands , It greatly facilitates the system operation , system management . The system has strong operability , The display can be replaced by a very simple output device , To operate computers and complete complex system development and management .
<>3. Good file system
Unix The file system of the system is a tree structure . It consists of a basic file system and several detachable sub file systems , It can expand the file storage space , It is also conducive to security and confidentiality .Unix System file , Unified processing of files, directories and equipment . It accesses files sequentially or randomly as a character stream without any records , And make the file , File directories and devices have the same syntax, semantics and protection mechanism , This simplifies the system design , It is also convenient for users to use . The cross platform file system and network file system provide great convenience for users .
<>4. Strong portability
Unix The system contains very rich language processing programs , Utility programs and instrumental software for developing software , It provides users with a fairly complete software development environment .Unix Most of the programs in the system use C Language programmed , Only about 5% The program is programmed in assembly language .C Language is a high-level programming language , It makes Unix The system is easy to understand , Modification and expansion , And it has very good portability .
<>5. Powerful network function
This is Unix An important feature of the system . As Internet Network technology and important means of heterogeneous system interconnection TCP/IP The agreement is in Unix Developed and developed on , And he became Unix An integral part of a system .Unix Almost all systems include TCP/IP Support of . meanwhile , stay Internet Network server ,Unix Server share 80% above , Dominant . It also supports all commonly used network communication protocols , It can be easily connected with other host systems , Various wide area networks and local area networks are connected .
This too Unix An important feature of the system . some Unix It is partially open source , There are also some branches that are open source . for example macOS Is based on Unix of bsd branch . Anyone can find loopholes together , improvement , Add new features , Improve safety performance , Improved knowledge utilization , It also promotes the development of ecology .
<> three . Unix Disadvantages of operating system
although Unix The system has many advantages , But there are also some disadvantages .
<>1. Not suitable for ordinary users
Unix The use of the operating system requires the user to master the obscure computer language , And the operation is complex , No intelligent correction , The command line is prone to ambiguity , Cause some problems in use . therefore ,Unix The system has a certain entry threshold , Not suitable for ordinary users .
<>2. Text stream as an interface is not convenient and reliable
Unix The system obtains a text stream from standard input , handle , Print a text stream to standard output . Communication between programs is done by pipeline , Let the text flow pass between programs . When the program prints to standard output , Data is converted to text , This is a coding process , Programs communicate with each other through pipes , Extracting information from text is a decoding process . Because the use of text streams is encouraged , Many programmers are free to design their coding without careful thinking . This caused
Unix Almost every program in has its own output format , This makes decoding a headache , Ambiguity and confusion often occur .
<>3. tradition Unix Poor kernel scalability
Unix Build tools in a minimalist way , Both large and complex tools can be created through a combination of small and simple tools , The same method does not continue to be applied on the kernel . tradition Unix The kernel has only a few basic functions for code reuse , Poor scalability . along with Unix Development of , Developers add code directly to the kernel , It will make the kernel bloated and complex , Anti modularization .