<<The Philosophical Principles of Computer's Mind Operating System>>Induction 1

1.CPU management is process management

There are 3 principles:

  • Fairness : every level has a chance to use the cpu
  • Non-blocking : any program cannot block the running of other programs endlessly. For example, a program needs to input data and blocks during the running process, then the process cannot block the running of other programs.
  • Priority : Programs with high priority, run first

2. Memory management is mainly to manage the memory structure formed by storage media such as memory, main memory, disk, and tape. For this purpose, the concept of virtual memory was invented to expand physical memory to external storage media. Another purpose of memory management is to allow many programs to share the same physical memory without interference, which requires segmentation and Protect.

 

3. Storage management

The main purpose of a file system is to turn a disk into an easy-to-use storage medium for users.

 

4. Device management is to manage input and output devices

Several principles of equipment management:

  • Shield the differences of different devices, users can access different devices in the same way
  • Provide concurrent access to devices that appear to be unshareable (such as printers) and become sharable

5. The operating system simply implements abstractions: process abstraction, file abstraction, and virtual memory abstraction.

 

 6. Interruption is the fundamental guarantee for the operating system to gain control of the computer

 

7. The kernel mode can access all the resources of the computer, and the user mode access rights are partially restricted. Everything that involves the fundamental operation of the computer itself should be implemented in the kernel state.


 

8. How does a computer identify a kernel-mode or user-mode program?

Making a judgment requires a flag, which is a status bit of the processor. The so-called user mode, the kernel mode is actually a state of the processor, not the state of the program. Through this status word, we can set the cpu to kernel mode, user mode, or other sub-states. When a program runs, what state is the CPU in, the program runs in the above state

 

9. Implementation of Kernel Mode and User Mode

How to limit the user mode? Obviously, every instruction of the program should be checked, and this check is the address translation . Kernel mode bypasses the process of address translation directly.

 

 

10. With the development of technology, the operating system gradually has a structure, starting with a single operating system structure, but this structure has many shortcomings, such as deadlock caused by cyclic calls between function blocks. Therefore, people design the operating system hierarchy, and the lower layer provides services to the upper layer functions.


    



 As the operating system is getting bigger and bigger, how to improve the execution efficiency and ensure the security has become a key issue, so the microkernel structure is proposed, and some non-core functions are put into the user mode.


 

11. The management of the process by the operating system is realized through the process table, which stores all the information about the process.

 

12. How does the operating system serve applications?

System call API

 

13. Shell (shell) and system calls

Using the API requires programming, how to facilitate the use of users who do not program? Many operating systems provide a shell (shell, divided into text and graphical interfaces), on the shell, the user enters code and indirectly calls the API.

 

 14. The process space is also called the address space, and the address space is all the resources used by the process. All resources constitute a division of the state. The characteristic of the address space is "passive", it can't do anything by itself, it needs threads to make these resources work.

 

Defects of the process: If the process is blocked during execution, such as waiting for input, the entire process will be suspended and cannot continue to execute. In this way, even if some of the work in the process does not depend on the input data, it cannot be advanced. Hence the invention of threads.

 

15. Since the thread is the avatar of the process, who manages it? There are 2 options, the process manages its own thread, or the operating system manages the thread

 

Advantages of kernel-mode threads: simple programming

                     Disadvantage: low efficiency

 

Advantages of user mode threads: programming complexity

                     Disadvantages: high efficiency, flexible and convenient

 

 

16. When a thread in a process is blocked, the whole process is blocked, what should I do at this time? If the process is switched directly, it will cause a lot of waste, because there may be other threads in this process that need to be executed. Therefore, when a thread is blocked, the operating system gives a "second chance" to ask the process if there are any other threads that need to be executed. But this method also has problems, which violates the principle that the upper layer calls the lower layer service in the operating system design principle.

 

Both kernel mode and user mode threads have serious defects, so the threading model of modern operating systems combines the two,

 

17. The purpose of introducing the threading model is to achieve process-level concurrency, because multiple threads often appear in a process,

There will also be problems in the shared address space of threads. These contradictions can be attributed to the following two aspects

  • How do threads communicate?
  • How to synchronize between threads?

18. Threads are the source of uncertainty at the software layer, and instruction multi-stage pipelines are the source of uncertainty at the hardware layer

 

19. Thread communication is done by means of pipes. The pipe is a linear byte array. In the Linux system download shell , the | symbol creates a pipe, for example:

$sort < file | grep would

 

Use the result of sort as input to grep

 

If you want to communicate between threads between different processes, you need to use a named pipe, which is generally only supported by the Linux operating system

 

20. Thread communication can also use socket, socket is powerful, and can support communication at different levels, different applications, and across networks

 

21. Sockets and pipes in thread communication require both parties to actively establish a connection. Now a mechanism is needed to handle the following communication requirements.

  • Want to force a party to respond immediately to our communication
  • We don't want to establish any connection beforehand, but decide on the fly that we want to communicate with a process
  • The amount of information transmitted is very small, and the use of pipes and sockets is too resource-intensive

In response to the above requirements, we use the signal

 

22. In a computer, a signal is a kernel object, or a kernel data structure . After the sender fills in the data structure and specifies the target process of the signal, a specific software interrupt is issued. The operating system then finds the receiver of the signal in the kernel object and notifies it.

 

The invention of the semaphore originated from the operation of the railway. Only one train runs on the track at any time, and the system for managing this railway is the semaphore.

 

23. Threads, sockets, and signals still cannot meet a communication requirement: a large amount of data needs to be shared

At this time, communication is carried out by means of shared memory. The method of use is that a process first creates a memory space for communication, and other processes map the space to its own (virtual) address space, so that when reading and writing the shared memory area in its own address, it is communicating.

 

24. The execution result of multi-threading is uncertain, how to solve this problem?

Thread synchronization, synchronization is to allow threads to execute according to certain rules, common resources have locks, a piece of program code is either executed at one time, or not executed, there will be no time when the execution is halfway, other threads preempt the cpu.

 

25. In thread synchronization, threads without locks have to wait all the time, and the waiting process consumes resources. How to solve this problem?

The thread sleeps and wakes up the thread when the lock is released after other threads have finished using the resource.

 

 26. Monitor

The semaphore has the problem of difficulty in programming and low efficiency, so the monitor process was invented.

1.CPU management is process management. There are three principles:
  • Fairness : every level has a chance to use the cpu
  • Non-blocking : any program cannot block the running of other programs endlessly. For example, a program needs to input data and blocks during the running process, then the process cannot block the running of other programs.
  • Priority : Programs with high priority, run first
2. Memory management is mainly to manage the memory structure formed by storage media such as memory, main memory, disk, and tape. For this purpose, the concept of virtual memory was invented to expand physical memory to external storage media. Another purpose of memory management is to allow many programs to share the same physical memory without interference, which requires segmentation and Protect. 3. Storage management The main purpose of the file system is to turn the disk into an easy-to-use storage medium for users. 4. Device management is to manage several principles of input and output device device management:
  • Shield the differences of different devices, users can access different devices in the same way
  • Provide concurrent access to devices that appear to be unshareable (such as printers) and become sharable

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326613289&siteId=291194637