版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、CHP5 The Linux Kernel,5.1 Characteristics of the Linux Kernel 5.2 Composition of the Linux Kernel 5.3 Process management 5.4 Memory management 5.5 File system management 5.6 Device management 5.7 Inter process communication mechanism 5.8 Kernel configuration,2,The kernel is the internal core program
2、 of the operating system, which provides the core management to computer devices. The operating system code is divided into two parts: kernel space (the address space of the kernel) External space/User space (the address space occupied by the external manager and user process) Usually, a program wil
3、l span(跨越) two spaces: The kernel mode (內(nèi)核態(tài)) when the program is executed into the kernel space The user mode (用戶態(tài)) when the program is executed into the outer space,5.1 Characteristics of the Linux Kernel,3,4,Monolithic Kernel(單一內(nèi)核) Used to be the mainstream of operating systems All functions in th
4、e operating system are encapsulated(封裝) in the kernel. The kernel and external programs are in different memory address spaces. Prevents external programs from directly accessing data structures in the kernel in various ways. A program can only access the kernel structure through an interface called
5、 System Call(系統(tǒng)調(diào)用). Micro Kernel(微內(nèi)核) (gradually popular in recent years) The operating system kernel only provides the basic and core part of the operation (for example, create and delete tasks, memory management, interrupt management, etc.) Other management programs (such as file system, network p
6、rotocol stack, etc.) are placed outside the kernel. These external programs can run independently and provide operating system services to external user programs.,5,Interprocess communication mechanism (IPC) is used to interact between services. Advantages of Micro kernel: Just like the benefits of
7、object-oriented programming Makes the internal structure of the operating system simple and clear. External management programs can be maintained and Disassembled(拆裝) separately. This makes the maintenance of the program code very convenient, and embodies the structural characteristics of the object
8、-oriented software. Disadvantages of Micro kernel: The isolation of program codes makes the whole system lose many optimization opportunities. Some of the resources are wasted on communication between external processes, the efficiency is low. The micro kernel structure is simpler than the monolithi
9、c kernel, and its efficiency is lower than the monolithic kernel.,6,Linux- monolithic kernel Linux focuses on powerful and efficient code. Linux is different from the traditional monolithic kernel UNIX operating system: Linux supports the dynamic loading of kernel modules(模塊). Linux supports Symmetr
10、ical Multi-Processing (SMP, 對稱多處理) mechanism. The Linux kernel is preemptive (搶占式). the Linux kernel can preempt a task even as it executes in the kernel. Linux does not differentiate between threads(線程) and normal processes(進(jìn)程). Linux provides the object-oriented(面向?qū)ο? device model with device clas
11、ses(設(shè)備類), hot-pluggable(熱插拔) events, and the user-space device filesystem.,7,The Linux kernel consists of five subsystems: Process scheduling(進(jìn)程調(diào)度) Inter process communication Memory management Virtual file system Network interface In addition, also includes device drivers and some general tasks and
12、 mechanisms.,5.2 Composition of the Linux Kernel,Process scheduling Process management mainly controls the access of system process to CPU. When a process needs to run, the process scheduler starts a new process according to the scheduling algorithm based priority. Linux supports multitasking, so ho
13、w to support multitasking on a single CPU? This work is implemented by process scheduling management. When the system is running, each process will be divided into a certain time slice(時(shí)間片), and then the process scheduler selects each process to run in turn according to the different time slices. Be
14、cause the switching time and frequency are very fast, the user feels that multiple programs are running at the same time,Inter process communication Interprocess communication is mainly used to control the synchronization(同步), data sharing and exchange between different processes in user space. Beca
15、use the different user processes have different process space, the communication between processes should be realized by means of kernel transfer(內(nèi)核的中轉(zhuǎn)). In general, when a process waits for the hardware operation to complete, it is suspended(掛起). When the hardware operation is completed, the proces
16、s is resumed(恢復(fù)). What coordinates(協(xié)調(diào)) this process(過程) is the inter process communication mechanism.,3)Memory management The main task of memory management is how to manage the physical memory of the whole system reasonably(合理地) and effectively, and respond to the requests of each subsystem of kern
17、el for memory allocation quickly. Linux memory management supports virtual memory, and the extra memory is obtained through disk application. Normally, the system only keeps the currently running program block in memory, and other program blocks in disk. In case of memory shortage, memory management
18、 is responsible for exchanging program blocks between disk and memory.,4)Virtual file system(VFS) The virtual file system in the Linux kernel uses a general file model to represent various file systems. This file model masks many specific file system differences, which makes the Linux kernel support
19、 many different file systems. This file system can be divided into logical file system and device driver: logical file system refers to the file system supported by Linux, for example, e.g. XT2, ext3 and fat; device driver refers to the device driver module written for each hardware controller. The
20、implementation of VFS mainly introduces(引入) a general file model(文件模型) . The core of the model is four object models(對象模型): Super block object (超級塊對象) Index node object (索引節(jié)點(diǎn)對象) File object (文件對象) Directory entry object (目錄項(xiàng)對象),5)Network interface Network interface provides support for the implement
21、ation of various network standards and various network hardware. Network interface is generally divided into network protocol and network driver. The network protocol part is responsible for the realization of every possible network transmission protocol. The network device driver is mainly responsi
22、ble for communicating with the hardware device. Every possible network hardware device has its corresponding device driver. The network interface of Linux is divided into four parts : Network device interface Receiving and sending data from physical media Network interface core Network protocol fami
23、ly(協(xié)議族) TCP/IP, IPX, X.25, AppleTalk Network interface socket level Providing a programming interface of network service for user,5.3 Process management,13,A process is a program running in its own virtual address space, include related resources. The Linux system includes the following types of pro
24、cesses: Interactive process(交互進(jìn)程): the process is controlled and run by shell. It can run in the foreground(前臺) or in the background(后臺). Batch process(批處理進(jìn)程): This process does not belong to a terminal and is submitted to a queue for sequential execution. Daemon (守護(hù)進(jìn)程): This process is called back
25、in the background only when needed. It usually starts when Linux starts.,14,Description of process: The process is dynamic, and the process is changing all the time when the processor executes the machine code. Processes include not only program instructions and data, but also program counters and a
26、ll CPU registers, as well as the process stack that stores temporary data. The ongoing process includes all the current activities of the processor. A process is a general term for a program in execution and related resources.(進(jìn)程是處于執(zhí)行期的程序以及相關(guān)資源的總稱) Linux is a multi-process operating system, each pro
27、cess has its own privileges and tasks, the failure of a process will not lead to the failure of other processes, processes can communicate with each other through the mechanism controlled by the kernel.,15,Resource allocation(資源分配) During the whole runing of the process, it will use a variety of sys
28、tem resources, will use the CPU to run its instructions, need physical memory to save its data. It may open and use various files, directly or indirectly using all kinds of physical devices in the system. The Linux system kernel must understand the process itself and the various resources used by th
29、e process in order to rationally allocate system resources among multiple processes. The most valuable resource in the system is CPU, because in general, a system has only one CPU. Linux is a multi-process operating system, so other processes must wait until the running process has free CPU to run.,
30、16,When a running process waits for other system resources, the Linux kernel takes control of the CPU and assigns it to other waiting processes. The scheduling algorithm in the kernel determines which process is allocated to CPU. Process management program A process manager can create, activate, run
31、, block(阻塞), rerun, release(釋放), and delete processes. Processes go through the following states in sequence: Create, ready or active, produce (create and activate), run, block, rerun, complete, and ready. Finally, release or delete (in a long process, blocking and rerun can happen many times).,17,T
32、he functions of the process management program: Manage the process and resources in the system. Enables processes to execute sequentially, or block when resources are needed, and to continue running when resources are available. For resource management (including process scheduling on CPU), the logi
33、cal link with resource management program is realized. Allocate resources according to the resource allocation mechanism of the system. Restrict certain resources to be shared only among certain processes.,18,process and thread Almost all embedded operating systems today are required to provide mult
34、itasking(多任務(wù)) capabilities. But most embedded systems have only one processor. To fulfill this requirement, the operating system must allocate execution time for these different tasks, which take turns to use the allocated execution time to complete the work. To facilitate the management of these ta
35、sks, the embedded operating system treats a work or a program as an execution unit, which has different names and meanings in different embedded operating systems, but the basic idea is to share and use limited hardware resources among different programs. When users using the system, feel as if they
36、 can execute multiple applications at the same time.,19,Linux uses the “inheritance(繼承)” approach to allocate resources. Each new process must inherit s set of system resource from the parent process(父進(jìn)程). A child process(子進(jìn)程)is allocated to another separate memory space, and then copied all the dat
37、a completely from the parent processs memory space, and then set the parameters to determine that whether to share resources with the parent process and decide whether the child process belongs to Heavy Priority Weight Process (重優(yōu)先權(quán)值進(jìn)程)or Light Priority Weight Process (輕優(yōu)先權(quán)值進(jìn)程). The process of light
38、 priority weight is also called thread(線程) in Linux.,20,2. The state of the process The embedded operating system must manage the execution and switching of multiple tasks, because there is only one task that is actually executed by the CPU at a certain time. So when there are many different tasks a
39、t the same time, the state of each task is different. A process can be in a group of different states during its lifetime. It is called process state. As shown in Figure 2.2. TASK_RUNNING(運(yùn)行狀態(tài)) when a process is being executed by the CPU or ready to be executed by the scheduler at any time, is calle
40、d running.,21,22,TASK_INTERRUPTIBLE(可中斷睡眠狀態(tài)) when a process is in an interruptible wait state, the system will not schedule the execution of the process. When the system produces an interrupt or releases the resource that the process is waiting for, or the process receives a signal, it can wake up t
41、he process to switch to the ready state (running state). TASK_UNINTERRUPTIBLE (不可中斷睡眠狀態(tài)) Its similar to TASK_INTERRUPTIBLE state. But a process in this state can be switched to a runnable ready state only when it is waken up by the wake_up () function. TASK_STOPPED (暫停狀態(tài)) When the process receives t
42、he signal SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU, it will enter TASK_STOPPED state. SIGCONT signals can be sent to the process to make it run.,23,TASK_ZOMBIE(僵死狀態(tài)) When a process has stopped running but its parent has not asked for its state, is said to be in TASK_ZOMBIE state. Processes running in ke
43、rnel state cannot be preempted by other processes, and one process cannot change the state of another process. To avoid kernel data errors during process switching, the kernel prohibits all interrupts when executing critical section code(臨界區(qū)代碼).,24,TCB, PCB The operating system will represent a proc
44、ess with a special data structure. This particular data structure records important data, often referred to as a PCB(Process Control Block) or a TCB(Task Control Block). In addition to containing task context(任務(wù)上下文), it also records handles(句柄), priorities, and subsidiary data(附屬數(shù)據(jù)) for some process
45、es that provide all the information needed for Scheduler scheduling. The process state is stored in the state field of TCB. The task data structure is defined in header file include/linux/sched.h.,25,The kernel program manages the process through the task vector table(任務(wù)向量表), and each process occupi
46、es one item in the vector table. The item is a task_struct pointer, which points to the related process . When a new process is created, the process management module allocates a new task_struct from system memory and adds it to the task vector table. To make it easier to find, use the current point
47、er to point to the currently running process.,26,When a process is executed, the values in all registers of the CPU, the state of the process, and the contents of the stack are called the context of the process(進(jìn)程上下文). When the kernel needs to switch to another process, it needs to save all the stat
48、e of the current process, that is, the context of the current process, so that when the process is executed again, it can be restored to the switched state and executed. In Linux, the context of the current process is stored in the task data structure of the process。,27,3. Creation of process Creati
49、on of process refers to defining address space (memory block) for the created process, and also defining resources for the process. The Linux system uses inheritance(繼承) to create processes. The process manager assigns TCB to the process and manages it. TCB is a process descriptor used by process ma
50、nagement programs. Other OS units can query(查詢)the TCB of the process when necessary. Init process(初始化進(jìn)程) When the system starts-up, it runs in the kernel mode. At this time, there is only one process: init process. The initialization process is a process that executes the memory instruction when th
51、e processor restarts and then calls the OS.,28,The processor then executes all the processes that were created. Like all other processes, the init process has a set of machine states represented by stack, register, and so on. When other processes in the system are created and run, these information
52、is stored into the task_struct data structure of the init process. At the end of system initialization, the initial process starts a kernel thread (init) and then executes an idle loop, doing nothing. That is, when the processor has nothing to do, the scheduler runs the idle process. The task_struct
53、 of this idle process is the only one that is not dynamically allocated but is statically defined at the time of kernel linking, called init_task, to avoid confusion.,29,The init process has the process identifier 1(標(biāo)識符), which is the first real process of the system. It executes some initial settin
54、gs of the system (such as opening the system controller, installing the root file system, etc.) and then executes the system initialization program. Depending on the system, the init program can be one of them:/etc/init, /bin/init or /sbin/init. The init program uses / etc / inittab as a script file
55、 to create new processes ,and the new processes themselves may create new processes too. For example, the Getty process may create a login process when the user tries to log in. All processes in the system are descendants(后代) of the init process .,30,The creation of the new process It is achieved by
56、 cloning the old process, or cloning the current process. A new task is created (fork or clone) through a system call, and cloning occurs in the kernel state. At the end of the system call, a new process is generated and waits for the scheduler to select it to run (to prevent the new process from be
57、ing executed by the scheduler before the new process is created, the new process state should be set to an uninterrupted wait state). One or more physical pages are allocated to the stack (user and kernel) of the cloning process in the physical memory of the system for the new task_struct data struc
58、ture.,31,A process identifier will be created, which is unique in the system process identifier group. The new task_struct enters the task vector table, and the contents of the old (current) processs task_struct are copied to the cloned task_struct. When cloning a process, Linux allows two processes
59、 to share resources instead of having different copies, including process files, signal processing, and virtual memory. When these resources are shared, their corresponding count fields (字段) increases or decreases so that Linux does not release these resources until both processes stop using them. For example, if a cloned process wants to share virtual memory, its task_struct includes a mm_struct pointer to the original process, and the count field of the mm_struct increases to indicate that the process currently sharing it.,32,4. Schedulin
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 生產(chǎn)經(jīng)營性企業(yè)規(guī)章制度
- 生產(chǎn)車間服裝廠現(xiàn)場管理制度
- 小榨菜仔油生產(chǎn)工作制度
- 儀器生產(chǎn)設(shè)備清洗制度
- 食用油車間生產(chǎn)管理制度
- 生產(chǎn)區(qū)域車輛管理制度
- 汽車生產(chǎn)企業(yè)倉儲管理制度
- 生產(chǎn)型企業(yè)查崗制度匯編
- 煙葉生產(chǎn)工作管理制度
- 鎮(zhèn)政府安全生產(chǎn)責(zé)任制度
- 《游園》課件統(tǒng)編版高中語文必修下冊
- 質(zhì)量責(zé)任劃分制度
- JT∕T 1496-2024 公路隧道施工門禁系統(tǒng)技術(shù)要求
- 2024版美團(tuán)商家合作協(xié)議合同范本
- 一年級上冊數(shù)學(xué)應(yīng)用題50道(重點(diǎn))
- 嵌入式系統(tǒng)實(shí)現(xiàn)與創(chuàng)新應(yīng)用智慧樹知到期末考試答案章節(jié)答案2024年山東大學(xué)
- 線纜及線束組件檢驗(yàn)標(biāo)準(zhǔn)
- 人教部編版語文三年級下冊生字表筆順字帖可打印
- 口述史研究活動方案
- 房屋租賃合同txt
- 珍稀植物移栽方案
評論
0/150
提交評論