Operating System Principle

Source: Internet
Author: User

Operating System Principle

We deal with the operating system every day. It is absolutely necessary to understand the operating system principles. It can help you understand the internal operating system.

How it works, why is there such a problem, and provides us with ideas to solve these problems.

This article is completely written for ordinary computer users. It omits all hard-to-understand algorithms and principles, and does not have much detail. It is only intended for General Electric

A brain user may be interested in issues that give Implementation ideas. Writing these things is just my willingness, so I am afraid that I will write more deeply, and beginners will not understand it.

If the 10 k text can give you a better understanding of the operating system, it would be a waste of these sweaty summer afternoons.

Q: What is interruption?

A: interruption. Here is an easy-to-understand example.

For example, when Lian and Tang are playing chess, they will soon be unable to stand up. At this crucial moment, Tang's girlfriend is coming, so Tang has to accompany her to the streets to buy clothes (Tang fainted :-)), so Tang and Tang may not discuss with Lian, first sealing the board, and then continue fighting after buying clothes. When the lamp was running, Tang and Tang went back to the board with their full face and tired. As a result, Lotus was defeated by the power of the game.

This is the entire interruption process. Let's take a look at how the interrupt process occurs:

1) Request interruption: Tang's girlfriend wants him to go shopping

2) interrupted response: Tang and Tang are preparing to put down the board and accompany his girlfriend to go shopping

3) On-site protection: the Board is first closed

4) interrupt handling: Tang spent time shopping with his girlfriend to buy clothes

5) restore the scene: unseal the Board

6) return of Interruption: continue fighting

In computers, the interrupt mechanism is very important. It is used to coordinate the system's response to and handling various external events and is a necessary condition for multi-task implementation. It can be said that there is no computer without an interrupt mechanism. Oh, by the way, if Tang moves the game to the bottom of the secret room and won't let his girlfriend disturb him, this is called "interruption blocking ".


Q: What does RING3 and RING0 mean?

A: This should start with the privilege level of the CPU Command System (commands used to control the CPU to complete various functions. Among all the CPU commands, some commands are very dangerous. If they are used incorrectly, the entire system will crash. For example, clear the memory and set the clock. If all programs can use these commands, it is not surprising that your system crashes n times a day. Therefore, the CPU divides commands into privileged commands and non-privileged commands. For Dangerous commands, only the operating system and its related modules are allowed. common applications can only use commands that do not cause disasters. In the image, privileged commands are not suitable for children, while non-privileged commands are suitable for all ages.

Intel's CPU has four levels of privilege: RING0, RING1, RING2, and RING3. In Windows, only two levels of RING0 and RING3 are used. RING0 is only used by the operating system. RING3 can be used by anyone. If a common application attempts to execute the RING0 command, Windows displays the "invalid command" error message. Despite the privilege-level protection of the CPU, it is a pity that Windows 98 has many vulnerabilities. It is also normal to use Windows 98 to crash n times a day.

Q: Why is an operating system required?

A: Haha, have you ever felt the charm of the operating system? With an excellent operating system like Windows, we had a problem with our machines all day long. We had to reinstall Windows one day to night, so that we can remember the names of companies like Microsoft and the names of outstanding programmers and bosses like Bill Gates ...... Well, to be honest, although Windows is unstable, it is absolutely undeniable that it is one of the best operating systems today. The operating system plays an important role in the computer. It provides a runtime environment for all applications and isolates applications from specific hardware. For example, if you change a sound card on the machine, you only need to reinstall the sound card driver to complete the process. However, if you do not have an operating system, you must purchase all the applications for the new sound card, so that these applications can recognize and use this sound card.
The operating system manages various computer resources, such as memory, disks, and CPUs. To use these resources, the application must be approved by the operating system (resource application), and the operating system schedules the usage time (resource allocation) in a unified manner ), after the application is used up, resources must be returned to the Operating System (Resource Recycling) for other applications to use. In this way, computer systems work in an orderly and efficient manner under the management of operating systems.

Q: What is a process? What are the differences between processes and programs?

A: A process is an execution activity of A program on A computer. When you run a program, you start a process. Obviously, the program is dead (static), and the process is active (dynamic ). Processes can be divided into system processes and user processes. All the processes used to complete various functions of the operating system are system processes, and they are the operating system itself in the running state. You do not need to talk about the user processes, all processes started by you are user processes. A process is the unit in which the operating system allocates resources. In Windows, a process is refined into a thread, that is, a process has multiple smaller units that can run independently.

Q: What is multitasking?

A: At the same time, if two or more processes are allowed to run in the same computer system, this is A multi-task. Modern Operating Systems are almost all multi-task operating systems that can manage the running of multiple processes at the same time. The benefits of multitasking are obvious. For example, you can listen to mp3 while surfing the internet, and even print downloaded documents without interfering with each other.



Q: What is "concurrency "? What is "Parallel "?

A: As the saying goes, it can't be used at all. This is the same for computers. In principle, a cpu can only be allocated to one process to run the process. We usually use only one CPU in the computer, that is, there is only one heart. To make it single-purpose and multi-process running at the same time, we must use the Concurrency Technology. The Concurrency Technology is quite complex, and the easiest to understand is the "time slice rotation process scheduling algorithm". Its idea is as follows:

Under the management of the operating system, all running processes use the CPU in turn. Each process allows a very short CPU usage (such as 10 ms ), in this way, the user does not feel that the CPU is serving multiple processes in turn, as if all processes are running continuously. But in fact, only one process occupies the CPU at any time. If a computer has multiple CPUs, the situation is different. If the number of processes is smaller than the number of CPUs, different processes can be allocated to different CPUs for running, multiple processes are actually running at the same time, which is parallel. However, if the number of processes is greater than the number of CPUs, you still need to use the Concurrency Technology. In Windows, CPU allocation is based on threads. A process may consist of multiple threads. The situation is more complicated, but simply put, the relationship is as follows:

Total number of threads <= number of CPUs: Parallel Operation

Total threads> CPU count: Concurrent Operation

The efficiency of parallel operation is obviously higher than that of concurrent operation. Therefore, in multi-CPU computers, the efficiency of multi-task operations is relatively high. However, if you run only one process (thread) on a multi-CPU computer, you cannot take advantage of multiple CPUs. It is worth noting that Windows 9x does not support multiple CPU Systems. If Windows 9x is installed on multiple CPU systems, it is useless to have more CPUs.


Q: What is "preemptible multitasking "?

A: The process has A priority. If the priority of a running process is higher than that of a running process, the system can forcibly deprive the CPU of the running process and let the process with the highest priority run first. It can be seen how powerful the privileged ideology of human society is in the computer world. :-) The actual operating system generally combines the time slice idea with the idea of CPU occupation for CPU allocation. There are many advantages of preemptible multitasking. For example, if a process cannot run unexpectedly and its CPU occupation is not forcibly deprived, the entire system will be paralyzed, since early Windows 3.1 was not a preemptible multitasking system, Windows 3.1 was very unreliable.


Q: Will multiple processes conflict with each other during concurrent or parallel operation?

A: If there is no protection mechanism, it will certainly. This type of conflict usually occurs in the competition for resources. Obviously, if a horse road is narrow enough to pass only one carriage, when there are two carriages that want to pass at the same time, a coach must carry forward the style, otherwise, the results will definitely turn around. The operating system carefully manages all of this to avoid conflicts between processes. programmers often need to carefully write programs according to certain established rules for operating system management. More specific methods and principles have far exceeded the acceptable level for beginners. I 'd like to skip them.


Q: What is virtual memory?

A: virtual storage is A very important storage management technology. Its core idea is to use A large hard disk space to make up for the insufficient actual memory space. Under virtual memory management, the storage space available for applications is much larger than the actual memory size. We call the memory actually installed on a computer a physical memory, and convert the storage space obtained through the virtual storage technology much larger than the actual memory space into virtual memory. The implementation of the virtual storage technology is also very complicated. if I talk about it in detail, it will certainly be thankless. Here I will only mention the simplest idea. The memory unit is numbered in the computer, called the memory address. If your computer has 1 m physical memory (days, 286 said? For example, the address range of the physical memory is 0 to 1048575 (1024x1024-1 ).

If you want to access a unit with the address of 1048576, it is obviously not possible, because the maximum is only 1048575. However, if I save everything in the physical memory to the hard disk, and then map 1048576 to the physical storage unit with the address 0 in some way, I don't get another full M storage space. When the program wants to access a unit with the address 0, I can transfer the content originally stored on the hard disk back to the physical memory. This idea is clever enough. It is the core idea of virtual storage technology. So I can get n 1 m space. Real virtual storage management is much more complex and clever than what I mentioned above, it allows different processes to run in different address spaces (that is, each process can think that it occupies all the storage space and can be used at will, you don't have to worry about how other processes in the system use the bucket. This is like running different processes on different computers) and considering the optimal memory usage efficiency.


Q: What happens if a process accesses a storage unit that is not in its own address space?

A: In Windows, you will surely see an "The program has performed an illegal operation and is about to be closed ......" And so on. It is often frustrating to see such a dialog box, but this is what the operating system must do. We call it "storage protection ". The purpose of storage protection is to prevent system processes from being damaged by user processes, and to prevent processes from being read/written into their own regions. The truth is very simple: during the exam, you are only allowed to answer your own exam. If you want to read others' exam, or even want to modify the content on others' exam, if you perform an illegal operation, you must be "Shut Down" by The invigilator (the premise is that the invigilator is working normally; otherwise, it will be messy and cause serious consequences ).

Note: In Windows, the system shuts down a process for many reasons, except for illegal read/write to other process storage zones (out-of-the-box addresses, for example, if the ring0 command is executed only by the operating system and the divisor is 0 in the program.


Q: What is a hard disk partition?

A: At the earliest stage, the operating system was unable to manage large hard disk space. Therefore, A large hard disk space was divided into several smaller areas for ease of management. In addition, you sometimes need to install multiple operating systems in the system, but also need to divide the hard disk into different areas, so that different operating systems are managed separately, do not interfere with each other. It is no longer possible to partition the hard disk because the operating system cannot manage the large hard disk. However, we still partition the hard disk. Apart from installing multiple operating systems, the main purpose is to facilitate the management of various files.

The operating system assigns different drive letters to Different Hard Disk Partitions. In this way, a large hard disk is logically divided into multiple small hard disks.


Q: What is the Master Boot Record of a hard disk partition?

A: The Master Boot Record is the lifeblood of each hard disk partition. It records important information such as the location of the hard disk space occupied by A partition. If the primary Boot Record of a partition is damaged, the partition is completely used up.


Q: What is an active partition?

A: The active partition is A partition with the ability to bootstrap after the system is powered on. There is A main Bootstrap program in the active partition's Master Boot Record. Every time the system starts, this program is transferred to the memory for running to boot the operating system stored on the hard disk. Different Operating System Boot methods are different, so the Main Boot Program varies with the operating system installed on the system.


Q: How does one store Disk Files in Windows?

A: First, Windows uses hard disk space in the unit of "cluster. The size of a cluster varies depending on the disk space. Generally, the smaller the cluster, the larger the utilization rate of the hard disk space. The larger the cluster, the faster the storage speed. Each file must be divided into multiple blocks in the cluster size and stored on the hard disk. To this end, a table is required to record the clusters on the hard disk where the chunks of a file are stored. This table is named "FAT" in Win9x. The FAT table is also stored on the hard disk. Therefore, the FAT table is the root of the file system. If it is destroyed, all the files on a disk are used up. In addition to a FAT table, Windows also backs up one.


Q: What is a file directory table?

A: The file directory table is equally important as the FAT table. It records the file names and attributes of all files and the starting position in the FAT table. When you need to read and write a file, Windows will find the file from the file directory table, read the storage information related to this file in the FAT table at the starting position of the file indicated in the file directory table to read and write the file.


Q: What is a virtual device?

A: different I/O devices are fast and slow. In the operating system, to effectively use various devices, you can use high-speed devices to simulate low-speed devices. Thus, you can obtain Virtual Devices. A typical example in Windows is a printer. It is not difficult to find that the printer did not work when printing was started, but the hard disk was ringing. Then all the printed documents entered the print queue and printed in queue. When the previous document is still printed on the printer, the next document has entered the print queue. The process of submitting this document does not have to wait for the printer to print the document, so it can continue to process other things. This is because Windows uses a hard disk to simulate a printer. All the printing work is actually "printed" to the hard disk. The hard disk speed is much faster than that of the printer, so it was done at once. At this time, another process reads the printed data from the hard disk and prints the data to the actual printer. This process works in the background without affecting other processes on the foreground.


Q: What is device independence )?

A: There are many external devices for computers. The same type of devices have different manufacturers and models. These products are always slightly different. This makes it very difficult to write applications, because an application cannot take into account the compatibility of all hardware. To this end, the operating system isolates specific hardware devices from the entire system. The specific hardware operations and hardware-related compatibility issues are all solved by the device driver, at the same time, the operating system provides applications with a unified method to manipulate the device. The application only needs to call the functions provided by the operating system according to the routine, so there is no need to care about what the actual device is, this is unrelated to the device. In this way, you only need to install the corresponding driver every time you add or modify the hardware on the system.


Q: What is buffering technology?

A: Buffer technology should be used when data arrives at A location that does not match the departure speed. Buffer technology is like a reservoir. If there is too much water in the upstream, and the downstream is too late to be discharged, the reservoir will play a "Buffering" role. When the water stops in the reservoir, wait for the downstream to continue drainage, and then send the water to the downstream. Generally, the CPU speed is much faster than that of the I/O device. Therefore, you can set a buffer zone. for data from the CPU, it is first placed in the buffer zone, then the device can read data slowly from the buffer zone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.