Operating system principles

Source: Internet
Author: User

We deal with the operating system every day, it is absolutely necessary to understand some of the operating system principles, it can let you know inside the operating system

How it works, why there is such a problem, for us to solve these problems to provide ideas.

This article is purely for ordinary computer users, omitted all the difficult to understand the algorithm, principle, there is not much detail on the things, just for the General Electric

Brain users may be interested in issues that give an idea of realization. Write these things just my wishful, I am afraid I still write deep, beginners can not understand.

If this 10K text allows you to have a deeper understanding of the operating system, it will not waste a few sweaty summer afternoons.



Q: What is interrupt?

A: Break, give an example that is easy to understand.

For example, Lotus and Tangtang in chess, see Lian Lian soon overwhelmed, just this critical, Tang

Don's girlfriend came, not to Don Tang accompany her to the streets to buy clothes not (Tangtang fainted:-) ), so Tangtang

Had to discuss with Ephraim, first sealed the board, to buy the clothes to continue to fight. Lampholder hours, Don

Tang with full face tired back to the chess board, the result Lotus Lotus not to blow ash only force will win the game.

This is the entire interrupt process. Let's see how the Interrupt process happens:

1) Interrupt Request: Tangtang's girlfriend wants him to go shopping.

2) Interrupt response: Tangtang ready to drop the game and go shopping with her girlfriend

3) Onsite protection: First Seal the chessboard.

4) Interrupt processing: Tangtang with his girlfriend to shop for clothes

5) Resume the scene: The board is unpacked

6) Interrupt return: Continue fighting

In a computer, the interrupt mechanism is very important to coordinate the system's response to various external events.

and is a necessary condition for multi-tasking. So to speak, if there is no interrupt mechanism,

There is no computer. Oh, by the Tangtang, if he moves his chess to the Chamber of Secrets to keep his girlfriend from disturbing,

This is called "Interrupt masking".


What do you mean by Q:ring3 and RING0?

A: This has to be said from the level of privilege of the CPU instruction system (the command that controls the CPU to complete various functions).

In all the instructions of the CPU, there are some instructions that are very dangerous, and if used incorrectly, will cause the whole system

Collapse. Such as: clear memory, set the clock and so on. If all the programs are able to use these instructions,

It's no surprise that your system freezes n back a day. Therefore, the CPU divides the instruction into privileged instructions and non-

Privileged instructions, for those dangerous instructions, only allow the operating system and its associated modules to use, ordinary

application can use only those instructions that do not cause a disaster. Figuratively speaking, the privileged command is that

Children, and non-privileged instructions are suitable for all ages.


Intel's CPU divides the privilege level into 4 levels: Ring0,ring1,ring2,ring3. Windows only

use two of these levels RING0 and RING3,RING0 only for the operating system, RING3 anyone can use.

If an ordinary application attempts to execute the RING0 instruction, Windows displays an "illegal instruction" error message

Interest. Although there is a CPU privilege level for protection, unfortunately WINDOW98 itself is a lot of vulnerabilities, using

It is normal for Windows 98 system to crash n back a day.


Q: Why do I have an operating system?

A: Haha, don't you feel the charm of the operating system? Because with the excellent like windows,

Operating system, our machines are in trouble all the way--that's the problem we need to

To reload windows all the way, so that we can firmly remember the company like Microsoft

Name, and the name of a good programmer and boss like Bill Gates ...

well, seriously, although Windows is unstable, there's absolutely no denying that it's the best exercise today.

As one of the system. The operating system plays an important role in the computer, which provides all applications

a running environment and isolate the application from the specific hardware. For example, in the machine to change a sound card, only

You'll have to reinstall your sound card driver, but if you don't have an operating system, you'll have to

re-purchase all the applications for this new sound card so that these applications can recognize the sound

Card and be able to use it.

The operating system is like the big housekeeper of the computer, which manages various resources of the computer, such as memory, disk,

CPU and so on. Applications that want to use these resources must be approved by the operating system (resource request),

and the operating system is uniformly scheduled to use the time (resource allocation), the application must be used after the resource

Back to the operating system (resource recycling) for use by other applications. In this way, the computer system

under the management of the operating system work methodically with the most likely high efficiency.


Q: What do you call a process? What is the difference between a process and a program?

A: A process is an execution activity on a computer by a program. When you run a program, you start a

Process. Obviously, the program is Dead (static), and the process is alive (dynamic).

Processes can be divided into system processes and user processes. Any process used to complete the various functions of the operating system

Is the system process, they are in the running state of the operating system itself, the user process does not have to

Tell me more, all the processes you start are user processes.

a process is the unit in which the operating system allocates resources. Under Windows , the process is further refined into threads,

that is, there are multiple independent operations under a process. smaller units.



Q: What is multi-tasking?

A: At the same time, if two or more processes are allowed in the same computer system to be shipped

This is multi-tasking. Modern operating systems are almost multitasking operating systems that can simultaneously

Manages the operation of multiple processes. The benefits of multitasking are obvious, like you can listen to MP3 and surf the internet,

At the same time, you can even print the downloaded documents without interfering with each other.



Q: What is "concurrency"? What is "parallel"?

A: As the saying goes, one cannot use two, this is the same for computers, in principle a CPU can only be assigned to a

process in order to run the process. We usually use only one CPU in the computer, which means

With only one heart, to make it multitasking and run multiple processes at the same time, you must use concurrency techniques.

The implementation of concurrency technology is quite complex, the most easy to understand is the "time slice rotation process scheduling algorithm", it

The idea is briefly described as follows:

Under the management of the operating system, all running processes take turns using the CPU, and each process allows to occupy

CPU time is very short (such as 10 milliseconds), so that users simply do not feel that the CPU is in turn for

Multiple process services, just as if all the processes were running continuously. But actually in any

There is only one process that occupies the CPU in a single time. If a computer has multiple CPUs, the situation is different

, if the number of processes is less than the number of CPUs, different processes can be assigned to different CPUs to run, so that

Multiple processes are really running at the same time, which is parallel. But if the number of processes is greater than the number of CPUs, you still need

To use concurrency technology. In Windows, CPU allocation is done in threads, and a process may

Made up of multiple threads, the situation is more complex, but in a nutshell, the following relationships are:

Number of bus <= CPUs: running in parallel

Number of bus threads > number of CPUs: concurrently running

The efficiency of parallel operation is obviously higher than that of concurrency, so the efficiency of multitasking in a multi-CPU computer

Relatively high. However, if you run only one process (thread) in a multi-CPU computer, you cannot play more

CPU's advantage. It is important to note that Windows 9x does not support multi-CPU systems if the multi-CPU system

Installed on Windows 9x, there is no more CPU is useless.


Q: What is called "preemptive multitasking"?

A: The process is prioritized. If the process that is about to be run takes precedence over the running process

high-level, the system can forcibly deprive the running process of the CPU, let the high priority process run first.

It can be seen that the privileged thought of human society in the computer world shows how vividly. :-)

The actual operating system generally combines the idea of time slices with the idea of being able to take over the CPU allocation.

The benefits of preemptive multitasking are many, such as when a process unexpectedly fails to run, if

Cannot forcibly deprive its CPU of possession, the entire system is paralyzed, because earlier Windows 3.1 did not

is a preemptive multitasking system, so Windows 3.1 is very unreliable.


Q: Do multiple processes conflict during concurrent/parallel runs?

A: If there is no protection mechanism, it will certainly be. This conflict generally occurs in the scramble for resources.

Obviously, if a road is narrow to pass through a carriage, then when two carriages want to pass at the same time,

A coachman must carry forward the style, let first let, otherwise the result must be Shingma.

The operating system carefully manages all this to avoid inter-process conflicts, and programmers often need to

Write the program carefully in accordance with some established rules so that the operating system can manage it.

the more specific method, the principle already far surpasses the beginner to accept the level, I still can omit it.


Q: What is virtual memory?

A: Virtual storage technology is a very important storage management technology, its core idea is to use the huge hard disk

space to compensate for insufficient actual memory space. Under Virtual memory management, applications can use the

The storage space is much larger than the actual memory size. We refer to the actual installed memory of a computer as

physical memory, which will get much more storage space than actual memory space through virtual storage technology

Become virtual storage. The implementation of virtual storage technology is also very complex, if the words are certainly

Is thankless, here only to mention the simplest thought. The memory unit is numbered in the computer

, called the memory address. If you have 1M of physical memory in your computer (for God, 286 says?) Oh

For example, the address range for physical memory is 0 to 1048575 (1024x768 x 1024-1).

if you want to access a unit with an address of 1048576, it is obviously not possible, because the maximum is only 1048575.

。 But if I save everything in my physical memory to my hard disk, then I'm going to go through some kind of

method Maps 1048576 to a physical storage unit with an address of 0, and I don't get another full

M storage space, when the program to access the address of the unit 0, I put the original stored on the hard disk

The content is recalled to physical memory. This is a smart idea, it's the core of virtual storage technology.

Mind. So I can get n 1M of space. True virtual Storage management compared to what I mentioned above

It is also more complex and ingenious, enabling different processes to run on different address spaces (i.e.

Let each process consider itself to occupy all the storage space, can be used arbitrarily, do not care about the system

How other processes use storage space. This is like having a different process running on a different computer)

, and consider the optimal memory usage efficiency.


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

A: Under Windows you will definitely see a "the program has performed an illegal operation and is about to be shut down ..."

dialog box. It's always frustrating to see such dialogs, but this is what the operating system must

Do, we call it "storage protection". The purpose of storage protection is to protect system processes from being used

Process is not allowed to read or write to a zone that does not belong to itself. The truth is very simple: the exam

Time, you are only allowed to answer on your own paper, if you want to see someone else's paper, even want to

Change the contents of other people's Test paper, you "carried out the illegal operation", must be the Examiner "close"

(If the Proctor is working properly, otherwise it will be a mess, there will be serious consequences).

Note: There are many reasons why a system shuts down a process in Windows, except for the illegal reading and writing of other

Process Store (address out-of-bounds), as well as executing RING0 that only the operating system can perform

there is a divisor of 0 in the instruction, the program, and so on.


Q: What is a hard disk partition?

A: The earliest time, the operating system can not manage the large hard disk space, so a large hard disk space

Divided into smaller areas for ease of management. In addition, it is sometimes necessary to install multiple operating systems in the system

system, you also need to divide the hard disk into different areas, so that different operating systems are managed separately from each other.

It is not possible to partition the hard disk because the operating system cannot manage the large hard drive

, but we still partition the hard disk, in addition to installing multiple operating systems, the main or

the management of various documents is more convenient.

The operating system assigns different drive characters to different hard disk partitions, which logically puts a large hard disk

Divided into multiple small hard disks.


Q: What is the master boot record for the hard disk partition?

A: The master boot record is the lifeblood of each hard disk partition, which records the disk space occupied by a partition

important information such as the location of the room. If a partition's master boot record is destroyed, the partition is finished.



Q: What is an active partition?

A: The active partition is a partition with bootstrap (boot system) capability after the system is power-up, on the active partition

Master boot Record, the program is called into memory each time the system starts

Run to boot (boot) The operating system that is saved on the hard disk. Different operating system boot-side

method is different, so this master boot program differs depending on the operating system that is installed on the system.


How does the Q:windows store disk files?

A: First, Windows uses space on the hard disk as a "cluster" unit. Depending on the size of the hard disk space, a

The size of a cluster is different. Generally speaking, the smaller the cluster, the greater the utilization of hard disk space, the larger the cluster,

The faster the storage speed. Each file must be divided into multiple blocks in the size of the cluster, and then stored there

On the hard drive. To do this, a table is required to record which clusters of files are stored on the hard disk by the chunks that are partitioned

, this table is the Fat table in Win9x. Fat tables are also stored on the hard disk. Therefore, the FAT table is a file

The lifeblood of the system destroys it, and all the files on a disk are gone. So, Windows, in addition to making

A fat table will also be used to back up one.


Q: What is a file directory table?

A: The file directory table is as important as the Fat table, which records the file name, attributes, and

The starting position in the fat table. When you need to read and write a file, Windows will find it from the file directory table

This file, if found, follows the starting position of the file in the Fat table as indicated in the File directory table

read the stored information about the file in the Fat table and write to it.


Q: What is a virtual device?

A: The speed of different I/O devices is fast and slow. In the operating system, in order to effectively use a variety of devices, you can

Use a high-speed device to simulate a low-speed device, resulting in a virtual device.

The typical example in Windows is the printer. It's easy to see that the printer does not start printing

work, but the hard disk is ringing, and then all the printed documents are entered in the print queue, queued for printing. In front

When a document is still printed on the printer, the next document has entered the print queue and submits the

the process of the document does not have to wait for the printer to finish printing the document, so you can continue to work on something else.

This is because Windows uses a hard disk to emulate the printer. All the print jobs are actually "printed" to the

On the hard drive. The hard drive is much faster than the printer, so it's done in a flash. There is another process at this time

Responsible for reading the printed data from the hard disk, printing to the actual printer, the process is working in the background,

other processes that do not affect the foreground.


Q: What is device agnostic (device independence)?

A: Many external devices of the computer, the same type of equipment has different manufacturers, different models of products. This

Some products are always slightly different. This poses great difficulty in writing applications because a

Application is unlikely to take into account all hardware compatibility. To do this, the operating system sets the specific hardware

isolation from the entire system, hardware-specific operations, hardware-related compatibility issues, etc.

By the device driver, while the operating system provides the application with a uniform way to manipulate the device,

Applications only need to invoke the functionality provided by the operating system as a routine, without concern that the actual device is

What, this is device agnostic.

In this way, each additional or altered hardware on a system requires only the appropriate driver to be installed.



Q: What is buffering (buffering) technology?

A: Buffer technology should be used where the data arrives and the departure speed does not match. Buffer technology is like

A reservoir, if the upstream to the water too much, downstream too late to drain, the reservoir plays a "cushion" role,

First let the water in the reservoir to stop some time, and so downstream can continue to drain, and then the water to the downstream.

Typically the CPU is much faster than the I/O device, so you can set the buffer for

The data from the CPU is first placed in the buffer, and then the device can slowly read the data from the buffer.



Operating system principles

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.