Q & A about operating system principles

Source: Internet
Author: User
Source: http://tech.sina.com.cn
------------------------------------------
Collation

We deal with the operating system every day. It is absolutely necessary to understand the operating system principles. It helps you understand how the operating system works, why is there such a problem? It 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 only provides implementation ideas for problems that may interest normal computer users. 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 machine all day long-this problem, we had to reinstall windows all day long, so that we can remember the names of companies like Microsoft and the names of outstanding programmers and bosses like Bill Gates ...... (Delete the above text)

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 don't 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 briefly introduced as follows: under the management of the operating system, all running processes use the CPU in turn, and each process can take a very short CPU usage time (for example, 10 ms). In this way, the user cannot feel that the CPU is serving multiple processes in turn, it is 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.

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.