Q1. What is GNU? What is the relationship between Linux and GNU?
A:
1) GNU is a recursive acronym for GNU is Not Unix, a project of the Free Software Foundation (FSF) that has developed many high-quality programming tools, including the emacs editor, the famous GNU C and C++ compiler (gcc and g++); 2) Linux development uses many GNU tools. The tools used to implement the POSIX.2 standard on Linux systems are almost all developed by the GNU project; the Linux kernel, GNU tools, and other freedoms. The software makes up the Linux system or Linux distribution that people often say.
Q2. What are the components of the Linux system? Where is the Linux kernel located?
A:
1) The Linux system consists of four parts: user process, system call interface, Linux kernel subsystem and hardware; 2) Linux kernel is between user process and hardware, including system call interface and Linux kernel subsystem.
Q3. What are the components of the Linux kernel? What are the main functions of each subsystem?
A:
(1) In addition to system calls, the Linux kernel consists of five main subsystems: process scheduling, memory management, virtual file system, network and interprocess communication (IPC); (2) the main functions of each subsystem are: 1 Process scheduling: It controls the access of the process to the CPU. When it is necessary to select a process to start running, the scheduler selects the most should run the process; 2) Memory management: it allows multiple processes to safely share the main memory area, supporting Virtual memory; logically can be divided into hardware-independent parts and hardware-related parts; 3) virtual file system (VFS): it hides the specific details of various hardware, provides a unified interface for all devices, supports up to Dozens of different file systems, divided into logical file systems and device drivers; 4) Network: It provides access to various network standard protocols and various network hardware support, divided into network protocols and network drivers. Two parts; 5) Interprocess communication: support various communication mechanisms between processes, including shared memory, message queues and pipes.
Memory addressing
Q1. What is a physical address? What is a virtual address? What is a linear address?
A:
1) Define the memory space provided by the physical memory stick on the motherboard as the physical memory space, where the actual address of each memory unit is the physical address; 2) define the memory space seen by the application programmer as the virtual address space (or Address space), where the address is called virtual address (or virtual address), generally described in the form of "segment: offset", such as A815: CF2D; 3) linear address space refers to a continuous, non-segmented The address range is 0~4GB, and a linear address is an absolute address of the linear address space.
Q2. How does the MMU convert a virtual address to a physical address in protected mode?
A:
In protected mode, a memory management unit (MMU) consists of one or a group of chips whose function is to map a virtual address to a physical address, that is, to perform address translation. The MMU is a hardware circuit that includes a segmentation component and a paging component. The two components, called the segmentation mechanism and the paging mechanism, respectively, convert the virtual address into a linear address, and the paging mechanism converts a linear address into a physical address.
Q3. Why use a two-level page table for a 32-bit linear address space?
A:
A page table is a data structure that maps a linear address to a physical address. A 4 GB linear space can be divided into 1 M 4 KB pages, each page table entry occupies 4 bytes, and a page table of 1 M page table entries. It needs to occupy 4MB space, and it is also required to be continuous, so it is implemented by two-level page table; the two-level page table is to page the page table again, and the first level is called page directory, which stores information about the page table; The 4MB page table is paged again and can be divided into 1K pages of 4KB size.
Q4. What is the role of the page cache? Why does Linux mainly use paging mechanism to implement virtual storage management? Why does it use a three-level paging mode instead of two levels?
A:
(1) The page cache automatically retains the 32-page page entries recently used by the processor, so it can cover the 128KB range of memory; (2) Linux mainly uses the paging mechanism to implement virtual memory management for the following reasons: 1) Segmentation of Linux The mechanism makes all processes use the same segment register, which makes memory management simple; 2) One of the design goals of Linux is to be able to be ported to most popular processing platforms, but many RISC processors support Segment functionality is very limited; to ensure portability, Linux uses a three-level paging mode because many processors use a 64-bit structure; Linux defines three types of page tables: page directory (PGD), intermediate directory (PMD), and Page Table (PT).
process
Q1. What are the concepts of procedures and processes? Why introduce the concept of "process"?
A:
1) A program is a normal file, a collection of machine code instructions and data stored in an executable image on a disk, an executable image is the content of an executable file; 2) a process Represents the execution process of a program. It is a dynamic entity that changes continuously with the execution of instructions in the program. At some point, the content of the process is called the process image. 3) The execution process of the program can be said. Is the sum of an execution environment, in addition to the various instructions and data in the program, there is some additional data; and the dynamic changes in the execution environment reflect the operation of the program, in order to describe the process of dynamic changes, introduced The concept of "process".
Q2. What is a process control block? What basic information does it contain?
A:
1) In Linux, the description structure of the process is called task_struct, and such a data structure is called a process control block (PCB); 2) the PCB is a fairly large data structure with more than 80 fields, according to its function. All domains are divided into: status information, link information, various identifiers, interprocess communication information, time and timer information, scheduling information, file system information, virtual memory information, and processor environment information.
Q3. What is the state of the Linux kernel?
A:
1) There are three basic process states of Linux: running state, ready state, and blocking state (or waiting state); there are four possible conversion relationships between these three states: running state -> blocking state, running state -> Ready state, ready state -> running state and blocking state -> ready state; 2) For the convenience of management, combine the ready state and the running state into one state - the operational state, and then some other changes, the process The states are divided into: an operational state, a sleep (or wait) state (divided into a deep sleep state and a shallow sleep state), a pause state, and a zombie state.
Q4. What are the ways to organize PCBs?
A:
PCBs are organized in the following ways: process linked lists, hash tables, runnable queues, and wait queues.
Q5. What are the main scheduling algorithms? What aspects should a good scheduling algorithm consider?
A:
1) The main scheduling algorithms include: time slice rotation scheduling algorithm, priority scheduling algorithm (non-preemptive priority algorithm and preemptive priority algorithm), multi-level feedback queue scheduling algorithm and real-time scheduling algorithm; 2) a good scheduling The algorithm should consider five aspects: fairness, efficiency, response time, turnaround time, and throughput.
Memory management
Q1. Why is the process's address space divided into "kernel space" and "user space"?
A:
Linux's virtual address space is 4GB. The kernel divides the 4GB space into two parts. The higher 1GB (virtual address 0xC0000000 to 0xFFFFFFFF) is used by the kernel, called "kernel space"; and the lower 3GB (virtual) Addresses 0x00000000 to 0xBFFFFFFF) are used by each process, called "user space"; because each process can enter the kernel through system calls, kernel space is shared by all processes within the system; thus, from a specific process perspective, Each process can have 4GB of virtual address space (also known as virtual memory).
Q2. How does Linux implement "request paging"?
A:
1) If the page being accessed is not in memory, that is, the page has not been stored in any physical page, then the kernel allocates a new page and initializes it appropriately. This technique is called "request tuning." "Page"; 2) "Request paging" is a dynamic memory allocation technology that defers the allocation of pages until it can no longer be postponed, that is, until the page to be accessed by the process is not in physical memory. Causes a page fault exception; the introduction of this technique is mainly because the process does not access all the addresses in its address space when it starts running.
Interrupts and exceptions
Q1. What is an interruption? What is an exception? What is the difference between the two?
A:
1) Interrupt control is generated to overcome the processor inefficiency caused by using the program query control service mode on the I/O interface. Its main advantage is that the processor response can only be obtained when the I/O interface needs service. Without the need for the processor to continually query; therefore, the initial interrupts are all for external devices, called external interrupts (or hardware interrupts); 2) exceptions are also called internal interrupts, which are used to solve machine runtimes. Some random events occur and the convenience of programming; 3) Interrupts are divided into external maskable interrupts (INTR) and external non-maskable interrupts (NMI), and all interrupt requests (IRQ) generated by I/O devices are caused. Interrupts can be masked, while faults caused by emergency events (such as hardware failures) generate non-maskable interrupts; 4) exceptions are further divided into faults and traps, which have the common feature of not using an interrupt controller. Cannot be masked (the exception is actually the terminal signal sent by the CPU).
Q2. What is the interrupt vector? How does Linux allocate interrupt vectors?
A:
(1) In order for the processor to easily identify each interrupt source, 256 vector interrupts are numbered from 0 to 255, that is, an interrupt type code n is assigned, and the 8-bit unsigned integer is called a vector, that is, an interrupt. Vector; (2) Linux allocates 256 interrupt vectors as follows: 1) vectors numbered 0~31 correspond to exception and non-maskable interrupts; 2) vectors numbered 32~47 (ie caused by I/O devices) Interrupts are assigned to maskable interrupts; 3) The remaining vectors numbered 48-255 are used to identify soft interrupts; Linux uses only one of them (ie 128 or 0x80 vectors) to implement system calls.
Q3. What is the interrupt descriptor table? What is a door descriptor?
A:
1) In the real address mode, the CPU uses 1KB of space starting from 0 as an interrupt vector table, and each entry in the table occupies 4 bytes; but in protected mode, it consists of 4 bytes of entries. The interrupt vector table can not meet the requirements; therefore, in the protection mode, the entries in the interrupt vector table are composed of 8 bytes, and the interrupt vector table is also called the interrupt descriptor table (IDT); 2) each table in the IDT The item is called a gate descriptor.
Q4. What types of gate descriptors are there? What are the different among its?
A:
The type code in the gate descriptor occupies 3 bits, indicating the type of the gate descriptor. It is mainly divided into the following categories: 1) Interrupt gate: its type code is 110, which contains an interrupt or exception handler. The selector and the intra-segment offset; 2) the trap gate: its type code is 111; 3) the system gate: is specially set by the Linux kernel to allow the user-mode process to access the trap gate. .
System call
Q1. What is a system call? Why introduce a system call?
A:
(1) The operating system provides a set of interfaces for the interaction between user-processed processes and hardware devices (such as CPUs, disks, printers, etc.). These interfaces make the program more portable, as different operating systems provide as long as they are provided. The same set of interfaces, then the same program can be compiled and executed correctly on top of these operating systems. This set of interfaces is called "system call"; (2) the reasons for introducing system calls are: 1) this makes programming Easier; 2) This greatly increases the security of the system; 3) Most importantly, these interfaces make the operating system more portable.
Synchronization in the kernel
Q1. What is the critical section? What is the state of competition? What is synchronization?
A:
1) Critical regions are the code segments for accessing and manipulating shared data. It is usually unsafe to access multiple resources concurrently with the same resource; 2) if two kernel tasks may be in the same critical region, it is a kind of Error phenomenon; if this happens, it is called a competitive state; 3) Avoiding concurrency and preventing a race condition is called synchronization.
Q2. Briefly introduce the method of deadlock and avoid deadlock.
A:
Deadlocks include deadlocks and ABBA deadlocks. 1) There are four reasons for deadlocks: mutual exclusion, non-preemption, request and hold, and loop wait; 2) ways to avoid deadlocks: destroy "inalienable" Conditions, breaking the "request and hold" condition, and breaking the "loop wait" condition.
Q3. What is the cause of concurrent execution in the kernel?
A:
"Concurrency" is divided into "pseudo-concurrent" and "true concurrency". There are several reasons for concurrent execution in the kernel: 1) interrupt: it may interrupt the currently executing code at any time; 2) kernel preemption: kernel The task in the middle may be preempted by another task; 3) sleep and its synchronization with user space: the process executed in the kernel may sleep, this will wake up the scheduler, schedule a new user process execution; 4) more symmetric Processing: Two or more processors can execute code at the same time.
Q4. Give the definition of the semaphore and explain the meaning of down() and up(). A:
1) The semaphore in Linux is a sleep lock, which was proposed by Dijkstra in 1968. If a task tries to acquire a semaphore that has been held, the semaphore pushes it into the waiting queue and then lets it sleep. When the process holding the semaphore releases the semaphore, a task in the waiting queue will be awakened to obtain this semaphore; 2) the semaphore supports two atomic operations P() and V(), the former Called the test operation, the latter is called the increase operation; later the system called the two operations down() and up(); 3) the down() operation requests a semaphore by decrementing the semaphore count by one; up( The operation is used to release the semaphore, which is also referred to as the "upping" semaphore because it increases the count of the semaphore.
File system
Q1. What is the Linux directory tree structure? What is the difference between it and the Windows directory tree structure? Why does the Linux file system use a fixed directory format?
A:
A file is an abstract concept. It is a repository for storing all data or information. 1) The directory tree structure of Linux is: the root directory (/) is on top, and the others are parallel; 2) The Windows operating system also adopts a tree structure. But the root of its tree structure is the drive letter of the disk partition. There are several partitions with several tree structures, and the relationship between them is juxtaposed. In Linux, regardless of the operating system managing several disk partitions, There is only one directory tree; 3) The reason for this is: Linux is a multi-user system, and such a fixed directory plan helps to manage system files and different user files; 4) File types in Linux Includes: regular files, catalog files, device files, pipe files, and linked files.
Q2. What is a virtual file system? What is a virtual file system interface?
A:
1) Incorporate the operation and management of various file systems into a unified framework, so that user programs can operate on different file systems and files through the same file system interface, that is, the same set of system calls; User programs can not care about the implementation details of different file systems, but use the unified, abstract, virtual file system interface provided by the system; this unified framework is the so-called virtual file system conversion, generally referred to as virtual file system (VFS); The VFS object types include: superblock objects, inode objects, directory entries (dentry) objects, and file objects; 3) the virtual file system interface is an abstract interface provided by the virtual file system. It consists primarily of a standard set of abstract operations that are called by the user in the form of a system call.
Device driver
Q1. Why are the devices divided into two categories: “block devices†and “character devices� A:
1) Linux regards the device as a file, which has three meanings: First, each device corresponds to a file name, and corresponds to an index node in the kernel. Second, most system calls to file operations are applicable to devices. Third, from the perspective of the application, the logical space of the device file is a linear space; for the same specific device, the file operation and the device driver are different levels of the same thing, and conceptually a system can be used. Divided into three levels of application, file system and device driver; 2) Linux divides devices into two categories, one is a device such as a disk that is input/output in blocks or sectors, and is called a device. Block devices; another type of device that performs input/output on a character-by-character basis in characters (bytes) like a keyboard, called a character device; file systems are usually built on block devices.
Q2. What is a device driver?
A:
The software that processes and manages hardware controllers in Linux is the device driver.
Q3. Which registers does the I/O port generally include? What are their respective functions?
A:
1) The I/O port includes three categories: control register, status register and data register. 2) According to different ways of accessing peripheral registers, the CPU is divided into two categories: one is "memory-mapped". The other way is "I/O-mapped".
LED TV
GUANGZHOU SOWANGNY ELECTRONIC CO.,LTD , https://www.jerry-power.com