[Recruitment Interview] Operating System

The blogger sorted out some operating system-related questions during the summer vacation for the interview of the insurance research. Reference books: "Operating System Tutorial (5th Edition)" edited by Fei Xianglin and Luo Bin; Wang Daoyan's operating system book. In the process of sorting out, some other materials on the Internet were also used for reference, most of which are no longer available for reference. If there is any infringement, we will notify you to delete it.

Article directory


1. System call concept and mechanism

The system call means that the resources in the computer are limited, and in order to use these resources better, it is necessary to control the access of these resources. The system call is a way to control these resources. That is to say, the operating system is the only entry to use these resources, and this entry is the system call provided by the operating system. Generally, system calls are implemented through interrupts.
The operating system provides a set of interfaces for user-mode processes to interact with hardware devices—system calls: 1. Free users from the underlying hardware programming; 2. Greatly improve the security of the system and make user programs reliable. Portability; user programs and concrete hardware have been replaced by abstract interfaces.
insert image description here

2. Operating system structure

slightly

3. Microkernel

The microkernel is relative to the big kernel. As the development of the operating system becomes more and more complex, it is necessary to move some functions of the operating system out of the kernel, thereby reducing the complexity of the kernel. Then the microkernel contains some core functions.

4. Virtual machine

slightly

5. Single program, multi-program

Single-channel program means that all programs are queued up for execution one by one. If A is blocked, B can only wait. At this time, the CPU can only be idle.
And multiprogramming means that all processes can be executed interspersed. If A is blocked, the B process can take advantage of this time to occupy the CPU for execution, which can improve the CPU utilization.

6. Running state, ready state, blocking state, new state, dead state

The state of the process.

7. Process, process model, thread, thread model

A process is an independent unit for scheduling and resource allocation by the operating system, and a thread is the smallest unit for scheduling by the operating system. Because process switching is usually expensive, the concept of thread is introduced. Threads can be scheduled independently, but they do not own resources independently. Threads are part of a process.

8. Process Control Block (PCB)

It is the most important data structure for process management and control. Every process has a PCB. When a process is created, the PCB is established, and it follows the whole process of the process until the process is cancelled.

9. Trapped in, preempted

10. FCFS process scheduling, time slice round-robin scheduling, priority scheduling, multiple queue scheduling, shortest process priority scheduling, two-level scheduling

slightly

11. Synchronization

The execution of multiple processes has a certain sequence. For example, a process needs a message provided by another process, and enters the blocking state before getting the message;

12. Mutual exclusion race condition

Process mutual exclusion refers to a constraint relationship between several processes due to mutual competition for resources.

13. Critical section

Program segments related to shared variables in concurrent processes.
Critical resource :
A resource represented by a shared variable that can only be used by one process at a time.

14. Busy waiting algorithm

15. Lock variables

16. Atomic operations

Either complete all at once, or none of the operations. An operation that will not be interrupted by the thread scheduling mechanism, and there will be no context switch (context switch) during operation.

17. Signal amount

Is an integer variable, used to solve the synchronization mutual exclusion problem. If the semaphore is greater than 0, it means that there are still resources available. If the semaphore is less than or equal to 0, it means that there are no resources available.

18. Monitor

It is a program structure in which multiple worker threads formed by multiple subprograms (objects or modules) in the structure mutually exclusive access to shared resources.

19. Message

It is used to transmit information and consists of a structure. After each WindowS application program starts to execute, the system will create a message queue for the program, and this message queue is mainly used to store the messages of the windows created by the program.

20. Classic IPC problem

21. Two-stage locking

22. Pipeline

It is a traditional process communication method. It is a special file and is one-way. For the sending process, the pipe is the output file, and for the receiving process, the pipe is the input file.

23. Various control methods of I/O

①Polling control method: continuously query the status of the controller to see if it is ready, and if it is ready, perform IO operations. This method takes up CPU and consumes resources.
② Interrupt mode: If an IO operation is to be performed, the device controller will send an interrupt signal through the interrupt request line. Then the CPU responds to the interrupt signal and executes the interrupt.
③DMA mode: There is a data path between the device and the memory, which can transfer data in blocks without device intervention.
④ channel mode.

24. Device Controller

It is the interface between the CPU and the device.

25. Device Driver

Including all codes related to user equipment, its task is to convert the IO logic request submitted by the user into physical IO operation for execution.

26.SPOOLing

Spool I/O technology. Spooling can virtualize a physical device into multiple logical devices. It opens up an input well/an output well on the disk, which is a storage area for buffering.
insert image description here

27. Deadlock

When the operating system allows multiple processes to execute concurrently, the process will always be blocked. For example, if two processes are waiting for a resource occupied by the other, the two will always be in a waiting state.

28. Deadlock prevention:

Conditions for deadlock :
互斥条件(Critical resources are exclusive resources)
占有和等待条件(The process will occupy the resource and will not actively release it, and wait for another process to give up the resource)
不剥夺条件(The process cannot let other processes take the resource forcibly before it finishes using the resource)
循环等待条件( There is a circular wait chain, each process is waiting for the resource held by the next process)

The way to prevent deadlock is to destroy the above four conditions.
死锁检测: Use a resource allocation diagram: use a circle to represent a process, and a box to represent a class of resources. The arrow from process to resource represents the request edge of the resource, and the arrow from resource to process represents the allocation edge of the resource. Then, based on the resource allocation graph, the deadlock theory is used to detect whether the current system is in a deadlock state.
死锁避免: To avoid the occurrence of deadlock, the banker's algorithm can avoid the occurrence of deadlock.
The basic idea of ​​the banker's algorithm : before resource allocation, first check whether such resource allocation will make the system in an unsafe state, if so, then do not perform resource allocation, if not, continue to perform resource allocation for a long time.
The implementation process of the banker's algorithm:

  • The total number vector of each type of resource in the system resource=[r1,r2,…,r3]
  • The current available number vector of each type of resource in the system avaliable=[v1,v2,...,v3]
  • The maximum demand matrix claim[i,j] for each resource by each process
  • The matrix allocation[i,j] of the number of various resources already occupied by each process
  • Each process currently applies for various types of resource quantity matrix Request[i,j]

If a process wants to apply for resources:

  • If Request[i, ]<=Need[i, ], go to step 2; otherwise, error processing will be performed because the application quantity exceeds the maximum demand quantity.
  • If Request[i, ]<=Available[ ], go to step 3, otherwise, the application amount exceeds the available amount, and the process waits.
  • The system heuristically allocates the resources requested by the process
  • Turn to execute the security test algorithm, if return to safe state, then admit the tentative allocation, otherwise discard the allocation.

29. Disk

It is a direct access storage device. Its structure includes cylinder/track/sector and so on.

30. Disk scheduling algorithm

①First come, first served
②Shortest search time priority algorithm (always execute the request with the shortest search time first)
③Scanning algorithm (moving arm scans in one direction each time, scans to the end, and then moves back in the opposite direction)
④Elevator Scheduling algorithm (improvement of the scanning algorithm, the mobile arm does not have to scan to the end, when there is no access request, the mobile arm does not move, when there is an access request, the mobile arm moves according to the demand) ⑤ Cyclic scanning algorithm (mobile arm 0->
maximum , 0 -> max)

31. Virtual memory

In the computer, the functions of partial loading and partial replacement are realized, and logically provide users with an addressable internal memory much larger than the physical memory capacity. Book P216

32. Address relocation/address mapping/address translation

The process of converting a logical address into a physical address.

33. Logical address

Refers to the segment-related offset address generated by the program. For example, in C language pointer programming, you can read the value of the pointer variable itself (& operation). In fact, this value is the logical address, which is relative to the address of the data segment of your current process, and has nothing to do with the absolute physical address. Only in the Intel real mode, the logical address is equal to the physical address (because the real mode has no segmentation or paging mechanism, and the CPU does not perform automatic address conversion); the logic is the offset within the limit of the program execution code segment in the Intel protected mode. Shift the address (assuming that the code segment and data segment are exactly the same). Application programmers only need to deal with logical addresses, while the segmentation and paging mechanism is completely transparent to you and only involved by system programmers. Although application programmers can directly manipulate memory, they can only operate in the memory segment allocated to you by the operating system.

34. Physical address

It refers to the sequential addressing of the addresses of each physical storage unit in the memory from a unified base address. Physical address, also known as absolute address, is the actual storage address of data in memory.

35. Fixed partition

Divide the memory into many regions of fixed size, and only one job can be loaded in each partition. These regions can be the same size or different sizes.

36. Variable partition (dynamic partition)

The memory is not divided in advance, but when the process is loaded into the memory, the partition is dynamically established according to the size of the process.

37. exchange

Move the program in the waiting state from the main memory to the first storage, and move the program that is ready to compete for the CPU from the first storage to the main memory.

38. Inner fragments

Waste of space inside a partition.

39. Outer Fragments

In the dynamic partition method, many small/unused fragments will be generated in the memory, which are called external fragments.

40. First adaptation method: (address)

Next fit method,
Best fit method: (capacity)
Worst fit method: (Search from the position where the last time ended)

41. Pagination

Divide the memory space/process into equal-sized chunks. During the process of execution, the process applies for space in the main memory in units of blocks.
Segmentation : Divide user processes into different segments, and the system creates a segment table for each process.

42. Page table

In order to facilitate finding the physical block corresponding to each page of each process in memory, a page table is established. Each process has a page table. The first part of the page table is the page number, the second part is the physical block number in memory, and the third part is the page offset.

43. Page frame

Blocks of memory are called page frames. Blocks in a process are called pages. Blocks in external storage are called blocks.

44. Multi-level page table

If the logical address space is too large, it may cause the problem that the page table is too large and occupies too much space. A multilevel page table provides an index. The second-level page table is divided into first-level page number and second-level page number

45.TLBs, translation backing memory (fast table)

It is used to store a copy of the recently accessed page table entry, which can speed up the address translation. Correspondingly, the page table in memory is often called the slow table.

46. ​​Page Replacement Algorithm

Not Recently Used Page Replacement Algorithm (NRU):
First In First Out Page Replacement Algorithm (FIFO): First In First Out.
Second Chance Page Replacement Algorithm,
Clock Page Replacement Algorithm,
Longest Unused Page Replacement Algorithm (LRU): Pick a page that has not been used for the longest time recently for elimination.
Software simulation LRU algorithm (NFU), aging algorithm,

47. Belady Abnormal

As the number of pages increases, the page fault rate does not decrease, but increases

48. System Jitter

As soon as a page is swapped in, it is swapped out again. The main reason is that the number of pages frequently accessed by a certain process is more than the number of pages allocated to it.

49. Working set model, working set

A collection of pages that a process needs to access within a certain period of time.

50. Documentation

A file is a collection of information stored in a computer with the computer hard disk as the carrier.

51. Catalog file

File directory and directory file are two names for the same thing. From the point of view of usage, it is called a file directory, and from the point of view of implementation, it is called a directory file.

52. Some other concepts

Character device files, block device files, hard links, symbolic links, directory entries, i-nodes, superblocks, open file tables, file system mounts, block caches, file system performance, consistency checks, file system security and protection mechanism.

53. Goals and Functions of the Operating System

(1) The operating system is the manager of computer resources
Processor management (process control, process synchronization, process communication, deadlock handling, processor scheduling)
memory management (improve memory utilization, memory allocation and recovery, address mapping, memory Protection and sharing, memory expansion)
file management (the information in the computer exists in the form of files)
device management (complete the user's I/O request, facilitate the user to use the device, and improve the utilization rate of the device)
(2) Operation The system provides users with an interface to use the computer hardware system command interface (users input operation commands through the console or terminal to provide various service requirements to the system)
program interface (composed of system calls, users use these system calls in the program to request operations The system provides services for it)
Graphical interface The most common graphical user interface GUI (finally realized by calling the program interface)
(3) The operating system is used as an expansion machine
without any software support. A computer system is a computer transformed by several layers of software. Operating systems transform bare metal into more powerful and easier-to-use machines. We refer to machines overlaid with software as extended machines or virtual machines.

54. Kernel mode and user mode

In a computer system, the CPU usually executes two programs of different nature: one is the operating system kernel program; the other is a user-programmed program or an application program on the outer layer of the system. The kernel program is the "manager" of the application. The "supervisor" can execute some privileged instructions, while the "managed program" cannot execute these instructions for security reasons. The so-called privileged instructions refer to instructions that users are not allowed to use directly in the computer, such as: I/O instructions, interrupt instructions, access to registers for memory protection, and instructions such as sending program status words to program status word registers.

55. Interrupts and exceptions

(1) The introduction of interrupts——in order to support parallel operations between the CPU and devices,
interrupts are also called external interrupts, which refer to the occurrence of events other than instructions executed by the CPU, such as I/O end interrupts and clock interrupts issued by devices. Interrupts of this type are generally events unrelated to the currently executing instruction.
(2) The introduction of exceptions—indicating problems that occur when the CPU executes the instruction itself.
Abnormalities, also known as internal interrupts, exceptions, or traps, refer to events that originate from the CPU executing instructions, such as illegal opcodes of programs, address out-of-bounds, arithmetic overflow, page fault exception etc. The handling of exceptions generally depends on the running site of the current program and cannot be shielded.
(3) The difference between interrupt and exception
insert image description here

(4) Interrupt the execution process
insert image description here

56. The difference between a process and a thread/ The difference between a process and a program

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/rellvera/article/details/127119720