Operating system: Summary of key points (frequent interviewers)
1. What is operating system:
(1) Operating system is a program for computer to manage software and hardware resources. It is the kernel and cornerstone of computer system
(2) Is essentially a program that runs on a computer system
(3) It provides users with an interface to interact with the computer system
(4) The operating system is divided into the kernel and the shell, the kernel is the system operating hardware, the shell is the program around the kernel
2. What is system scheduling:
(1) First, we need to know the process of user mode and system mode
(2) User mode: the programs run by the users themselves, that is, some programs run by ourselves, can access the data of the users themselves
(3) System state: The system state is the process that can access any resources of the computer, such as file management
(4) System scheduling assumes that the user needs to schedule the system state process in the user process through the system scheduling, such as memory allocation, process management, etc
3. The difference between a process and a thread
Based on the operating system, a process is the smallest unit of memory allocation, and a thread is the smallest unit of CPU execution. Based on the JVM, threads share the heap and method area, and threads have their own virtual machine stack, local method stack, and program counters
3. Communication between processes:
(1) Pipelines
(2) signals
(3) Message queue
4. Synchronization between threads:
A) Why is synchronization needed: mainly to protect the security of shared resources and avoid conflicts
B) Operating systems generally solve synchronization problems in three ways
I. Mutex: To manipulate a shared variable, you must obtain a mutex, such as sychonized. Various lock implementations are based on mutex holding
Ii. Semaphore: It allows multiple threads to access the same resource at the same time, but controls the number of threads
Iii. Events: For example, wait and nodify realize multi-thread synchronization through notification and control the priority of threads
5. Process scheduling algorithm
A) First come, first served: Sort according to the order of requests, and the first requested is the first scheduled execution
B) Time slice rotation: the thread is allocated a certain time slice and executed within the time slice, assuming that the context switch is not completed
C) Priority: assign priority to processes and schedule threads according to priority order. Priority depends on memory and time
D) Short job first: the processes with short execution time are scheduled first
E) Multi-level feedback queue: The current mainstream thread scheduling method, through multiple queues corresponding to threads of different priorities, the threads that need CPU scheduling for a long time are moved to the queue with a lower priority, and the IO intensive or thread interaction threads are moved to the queue with a lower priority
6. Memory management of the operating system:
(1) Memory management is mainly responsible for memory allocation and recycling, address capture (such as logical address to physical address)
(2) Memory management mechanism:
A) Continuous management and discontinuous management
B) The continuous management mode allocates a continuous block of memory in memory, and the user program is allocated to run in one block of memory, which is the block management mode;
Discontinuous management way is the way of the user program to hash stored in memory, such as storage pages, sections of storage, storage for the memory allocation for a page to page a page, smaller than the block type, better CPU utilization, through the page table to store some logical information, followed by sections of storage, page this way than the division of power is bigger, The hashes of the user program are stored in memory, and the last one is called segmental pagination, which is implemented on a segmented basis, and hashes between segments and within segments
7. Logical address and physical address
A) The logical address is. It is the logical address that interacts with users in normal development
B) Physical address: the address of the CPU and memory where data is actually exchanged, and the unique identifier in memory
8. Fast tables and multilevel page tables:
A) Fast table: in order to solve the virtual address to physical address conversion rate, a way to speed up access to the data in the page table, can be understood as a cache, cache physical address, through the logical address can be quickly accessed
B) Multi-level page table: a typical example of time-space, mainly based on the principle of limitations
9. Similarities and differences between pagination and segmentation:
A) Similarities: Both paging and fragmentation mechanisms are designed to improve CPU utilization. Both paging and fragmentation are hashed in memory, but internally continuous
B) Differences: The size of the page is fixed and determined by the operating system, while the size of the segment is not fixed and depends on the program currently running. Compared with the page, the segment has better flexibility and can reflect the data segment and code segment
10. CPU addressing and why do you need virtual addresses
A) CPU addressing is primarily for accessing physical addresses through virtual addresses, through memory management units
B) Why there is a virtual address space:
I. If there is no virtual memory, users can directly operate the physical memory. As a result, the operating system crashes and multiple processes fail to run properly due to address conflict
Ii. Benefits of virtual addresses: The main reason is to isolate processes through virtual addresses to avoid changes to the actual physical addresses. Secondly, when the memory space is small, the memory manager will use virtual addresses to store physical memory to hard disks
11. Virtual memory
A) when the user starts the multiple processes that lead to far more than the physical memory, memory at this point why program still can continue to work, it is because of the existence of virtual memory, through the virtual memory, can let the process has a bigger than physical memory space, and virtual memory provides a consistent process, independent space; Its main purpose is to achieve an extension of physical memory to hard disk through virtual memory
B) Locality principle: this is the basis to solve why only part of the loading program memory can be run in memory, divided into time locality and space locality
I. Time locality: Time locality is mainly reflected in that instructions or data may be repeatedly accessed, so I save the recently used instructions or data in the tell cache to improve the speed of instruction and data access
Ii. Spatial locality: Spatial locality is mainly reflected in the execution of instructions due to sequential storage. The characteristics of sequential execution are generally within an address range, and the storage of data is generally in the form of clustering, such as array and linked list, and then the data to be retrieved is put into the cache
Iii. Virtual memory actually implements a “memory-external storage” two-level memory structure, and uses the principle of locality to achieve high speed cache
12. Virtual storage
A) virtual memory theory is one greater than the memory space for the application area, why is called virtual memory, in fact is through the virtual memory the program can only part of the enforcement procedure can run the program, memory does not exist in the program will run to the CRT loaded into memory, the memory without program will be scheduled to the peripheral storage
13. Realization of virtual memory technology:
(1) The realization of virtual memory needs to be based on discrete allocation of memory management method
(2) Main implementation methods:
A. Request paging storage management: Based on paging storage management, when a program needs to be loaded into the memory to run, it only needs to add some pages to run. If the page that needs to be scheduled is not found in the memory, the page scheduling algorithm is used to eliminate pages and add policies that need pages
B. Request segmented storage management: Based on segmented storage management, the program can also be run only by adding part of the fragment. Assuming that a certain segment is not in memory, it will be added to the memory for execution through the segment replacement method
C. Request segment-page storage management: the combination of paging segmenting, and then paging
14. Page replacement algorithm:
(1) an elimination strategy for an in-memory page, in order to add needed pages to the in-memory execution
(2) FIFO, LRU (most recently unused), LFU (least recently used)
(3) OPT: Whether to use it later