版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、操作系統(tǒng)第二章 處理器管理,南京大學(xué)軟件學(xué)院 2013,第二章 處理器管理,2.1 中央處理器 2.2 中斷技術(shù) 2.3 進(jìn)程及其實(shí)現(xiàn) 2.4 線程及其實(shí)現(xiàn) 2.5 Linux進(jìn)程和線程 2.6 Windows 2003進(jìn)程和線程 2.7 處理器調(diào)度 2.8 處理器調(diào)度算法 2.9 Linux調(diào)度算法 2.10 Windows 2003調(diào)度算法,2.1中央處理器,計(jì)算機(jī)組織結(jié)構(gòu) 處理器寄存器 指令執(zhí)行 多處理器系統(tǒng)與多核處理器系統(tǒng),2.1中央處理器1. 計(jì)算機(jī)組織結(jié)構(gòu),Processor Main Memory referred to as real memory or primary mem
2、ory Volatile(揮發(fā)的 持久的 persistent) I/O modules Secondary memory devices Input/Output devices, terminals Communications equipment System bus communication among processors, memory, and I/O modules,Top-Level Components,User-visible Registers Enable programmer to minimize main-memory references by optimi
3、zing register use Control and Status Registers Used by processor to control operating of the processor Used by operating-system routines to control the execution of programs,2.1中央處理器2. 處理器寄存器,User-Visible Registers,May be referenced by machine language Available to all programs - application program
4、s and system programs Types of registers Data Address,User-Visible Registers,Address Registers Index: involves adding an index to a base value to get an address Segment pointer: when memory is divided into segments, memory is referenced by a segment and an offset Stack pointer: points to top of stac
5、k,Control and Status Registers,Program Counter (PC) Contains the address of an instruction to be fetched Instruction Register (IR) Contains the instruction most recently fetched Program Status Word (PSW): record all status of an executing program. (the term used by OS) Program counter condition code
6、s Interrupt enable/disable Supervisor/user mode,Control and Status Registers,Condition Codes or Flags Bits set by the processor hardware as a result of operations Can be accessed by a program but not altered Examples positive result negative result zero Overflow,特權(quán)指令和處理器狀態(tài),從資源管理和控制程序執(zhí)行的角度出發(fā),必須設(shè)置特權(quán)指令
7、,提供給操作系統(tǒng)的核心程序使用 處理器狀態(tài) 管理狀態(tài)(特權(quán)狀態(tài)、系統(tǒng)模式、特態(tài)或管態(tài)): 處理器可以執(zhí)行全部指令,使用所有資源,并具有改變處理器狀態(tài)的能力 用戶狀態(tài)(目標(biāo)狀態(tài)、用戶模式、常態(tài)或目態(tài)): 處理器只能執(zhí)行非特權(quán)指令 核心狀態(tài)、管理狀態(tài)和用戶狀態(tài),Pentium的處理器狀態(tài),0級(jí)為操作系統(tǒng)內(nèi)核級(jí):處理I/O、存儲(chǔ)管理、和其他關(guān)鍵操作 1級(jí)為系統(tǒng)調(diào)用處理程序級(jí):用戶程序可以通過(guò)調(diào)用這里的過(guò)程執(zhí)行系統(tǒng)調(diào)用,但是只有一些特定的和受保護(hù)的過(guò)程可以被調(diào)用 2級(jí)為共享庫(kù)過(guò)程級(jí):它可以被很多正在運(yùn)行的程序共享,用戶程序可以調(diào)用這些過(guò)程,讀取它們的數(shù)據(jù),但是不能修改它們 3級(jí)為用戶程序級(jí),IBM的程
8、序狀態(tài)字寄存器,CMWP位依次為基本/擴(kuò)充控制方式位、開/關(guān)中斷位、運(yùn)行/等待位、目態(tài)/特態(tài)位,2.1中央處理器3.指令執(zhí)行: 指令與指令寄存器,Types of instructions Processor-memory: transfer data between processor and memory Processor-I/O: data transferred to or from a peripheral device Data processing: arithmetic or logic operation on data Control: alter sequence of
9、 execution Fetched instruction is placed in the instruction register,Instruction Cycle,Instruction Fetch and Execute,The processor fetches the instruction from memory Program counter (PC) holds address of the instruction to be fetched next Program counter is incremented after each fetch,Example of P
10、rogram Execution,I/O Function,I/O exchanges occur directly with memory Processor grants I/O module authority to read from or write to memory Relieves the processor responsibility for the exchange Example: Direct Memory Access (DMA),多處理器系統(tǒng)分類: 共享存儲(chǔ)(緊密耦合)多處理機(jī)系統(tǒng) 分布存儲(chǔ)(松散耦合)多處理機(jī)系統(tǒng)。 多處理器指在一個(gè)體系結(jié)構(gòu)上放置多個(gè)CPU芯片,
11、而多核則指在同一塊CPU芯片上放置多個(gè)核(core),即執(zhí)行單元。,2.1中央處理器4.多處理器系統(tǒng)與多核處理器系統(tǒng),多處理器系統(tǒng)與多核處理器系統(tǒng),x86體系結(jié)構(gòu)下,處理器4個(gè)演變階段。 (1) 多處理器結(jié)構(gòu)、 (2) 超線程結(jié)構(gòu)、 (3)多核結(jié)構(gòu)、 (4)多核超線程結(jié)構(gòu)。,(1)多處理器結(jié)構(gòu),多處理器系統(tǒng)與多核處理器系統(tǒng),(2)超線程結(jié)構(gòu),多處理器系統(tǒng)與多核處理器系統(tǒng),雙核,多處理器系統(tǒng)與多核處理器系統(tǒng),(3)多核結(jié)構(gòu),Intel 酷睿 i7 四核CPU,四核,多處理器系統(tǒng)與多核處理器系統(tǒng),(3)多核結(jié)構(gòu),(4)多核超線程結(jié)構(gòu),多處理器系統(tǒng)與多核處理器系統(tǒng),操作系統(tǒng)與多核處理器,處理器通信支
12、持 進(jìn)程/線程數(shù)據(jù)共享支持 存儲(chǔ)器層次及管理 程序并行執(zhí)行模型支持 同步支持 調(diào)度及優(yōu)化 能耗管理,多處理器系統(tǒng)與多核處理器系統(tǒng),2.2中斷技術(shù),中斷概念與中斷事件處理 中斷優(yōu)先級(jí)和多重中斷 Linux中斷處理 Windows 2003中斷處理,中斷的定義,中斷是指程序執(zhí)行過(guò)程中,遇到急需處理的事件時(shí),暫時(shí)中止CPU上現(xiàn)行程序的運(yùn)行,轉(zhuǎn)去執(zhí)行相應(yīng)的事件處理程序,待處理完成后再返回原程序被中斷處或調(diào)度其他程序執(zhí)行的過(guò)程。,2.2中斷技術(shù),1.中斷概念與中斷事件處理,An interruption of the normal sequence of execution Improves proce
13、ssing efficiency Allows the processor to execute other instructions while an I/O operation is in progress A suspension of a process caused by an event external to that process and performed in such a way that the process can be resumed,2.2中斷技術(shù),Classes of Interrupts,Program arithmetic overflow divisi
14、on by zero execute illegal instruction reference outside users memory space Timer I/O Hardware failure,Interrupt Handler,A program that determines nature of the interrupt and performs whatever actions are needed Control is transferred to this program Generally part of the operating system,Interrupt
15、Cycle,Interrupt Cycle,Processor checks for interrupts If no interrupts fetch the next instruction for the current program If an interrupt is pending, suspend execution of the current program, and execute the interrupt handler,中斷與中斷源,強(qiáng)迫性中斷事件 硬件故障中斷事件(硬件故障引起) 電源故障, 主存儲(chǔ)器故障, 程序性中斷事件(執(zhí)行機(jī)器指令引起) 除數(shù)為零, 操作數(shù)溢
16、出, 非法指令, 目態(tài)下使用特權(quán)指令, 地址越界, 外部中斷事件(外部事件引起) 時(shí)鐘中斷, 重啟動(dòng)中斷, I/O中斷事件(I/O控制系統(tǒng)發(fā)現(xiàn)外設(shè)完成I/O或I/O出錯(cuò)引起) 打印完成, 打印缺紙, ,中斷與中斷源,自愿性中斷事件 (進(jìn)程執(zhí)行訪管指令請(qǐng)求OS服務(wù)引起) 請(qǐng)求分配外設(shè), 請(qǐng)求I/O, 關(guān)于中斷的分類 中斷、異常與系統(tǒng)服務(wù)(中斷俘獲、陷阱、系統(tǒng)陷阱) 內(nèi)中斷、外中斷、軟中斷、自由中斷,兩類中斷事件的中斷處理過(guò)程,兩類中斷事件與中斷處理過(guò)程,中斷裝置,中斷寄存器: 記錄強(qiáng)迫性中斷事件的寄存器,每一種中斷可設(shè)置一個(gè)中斷寄存器 中斷字: 中斷寄存器的內(nèi)容, 記錄了所發(fā)生中斷的類型和原因(
17、如I/O中斷的中斷字為”通道號(hào),設(shè)備號(hào)”) 中斷裝置是一種硬件, 當(dāng)中斷事件發(fā)生后, 它能改變處理器內(nèi)操作的順序,中斷裝置與中斷響應(yīng),發(fā)現(xiàn)中斷源,提出中斷請(qǐng)求 發(fā)現(xiàn)內(nèi)容非零的中斷寄存器 決定這些中斷是否應(yīng)該屏蔽 當(dāng)有多個(gè)要響應(yīng)的中斷源時(shí),根據(jù)規(guī)定的優(yōu)先級(jí)選取一個(gè) 把中斷字送到當(dāng)前PSW的中斷碼字段 中斷當(dāng)前程序的執(zhí)行 保存當(dāng)前程序的PSW到內(nèi)存約定單元 啟動(dòng)操作系統(tǒng)的中斷處理程序 從內(nèi)存約定單元取出中斷處理程序的PSW,中斷裝置與中斷響應(yīng),中斷的處理,中斷處理程序 處理中斷事件的控制程序, 主要任務(wù)是處理中斷事件和恢復(fù)正常操作 中斷處理過(guò)程 保護(hù)未被硬件保護(hù)的一些必需的處理狀態(tài) 通過(guò)分析被中斷
18、進(jìn)程的PSW中斷碼字段,識(shí)別中斷源 分別處理發(fā)生的中斷事件 恢復(fù)正常操作,處理器中斷事件的處理,電源故障的處理: 處理器現(xiàn)場(chǎng)信息送主存 停止外圍設(shè)備工作 停止處理器工作 故障排除后, 從約定點(diǎn)重新啟動(dòng)操作系統(tǒng) 必要時(shí)操作員干預(yù) 主存儲(chǔ)器故障的處理 中止有關(guān)程序的運(yùn)行, 向操作員報(bào)告,程序性中斷事件的處理,對(duì)于無(wú)法克服的程序性中斷事件(如非法指令, 目態(tài)下使用特權(quán)指令, 地址越界, ): 向操作員報(bào)告請(qǐng)求干預(yù) 對(duì)于除數(shù)為零, 操作數(shù)溢出等程序性中斷事件: 可以由用戶程序自行處理, 或由操作系統(tǒng)進(jìn)行標(biāo)準(zhǔn)處理,外部中斷事件的處理,時(shí)鐘中斷事件: 每隔一個(gè)時(shí)間間隔發(fā)生一次, 操作系統(tǒng)自動(dòng)更改系統(tǒng)時(shí)鐘和
19、間隔時(shí)鐘的計(jì)時(shí);且當(dāng)間隔時(shí)鐘寄存器的值為臨界值時(shí), 操作系統(tǒng)進(jìn)行專門處理 控制臺(tái)中斷事件(重啟動(dòng)中斷, 關(guān)機(jī)中斷, ): 操作員利用控制臺(tái)發(fā)出命令, 請(qǐng)求服務(wù), 操作系統(tǒng)響應(yīng)并服務(wù),自愿性中斷事件的處理,用戶程序執(zhí)行系統(tǒng)調(diào)用(訪管指令,廣義指令); 操作系統(tǒng)把系統(tǒng)調(diào)用參數(shù)作為中斷字, 分析檢查后進(jìn)行相應(yīng)處理,中斷控制流程,2.2中斷技術(shù),2.中斷優(yōu)先級(jí)與多重中斷,中斷優(yōu)先級(jí)與中斷屏蔽,中斷優(yōu)先級(jí):當(dāng)計(jì)算機(jī)同時(shí)檢測(cè)到多個(gè)中斷時(shí), 中斷裝置響應(yīng)中斷的順序。常見的處理次序可能是處理器中斷事件、自愿性中斷事件、程序性中斷事件、時(shí)鐘中斷等外部中斷事件、輸入輸出中斷事件、重啟動(dòng)和關(guān)機(jī)中斷事件 中斷屏蔽:當(dāng)
20、計(jì)算機(jī)檢測(cè)到中斷時(shí), 中斷裝置通過(guò)中斷屏蔽位決定是否響應(yīng)已發(fā)生的中斷,中斷優(yōu)先級(jí)與中斷屏蔽,決定中斷處理次序的因素 中斷屏蔽可以使中斷裝置不響應(yīng)某些中斷 中斷優(yōu)先級(jí)決定了中斷裝置響應(yīng)中斷的次序 中斷可以嵌套處理, 但嵌套的層數(shù)應(yīng)有限制 中斷的嵌套處理改變了中斷處理的次序,(1) Linux內(nèi)核處理流程,2.2中斷技術(shù),3.Linux中斷處理,快中斷與慢中斷, Linux中,區(qū)分快中斷和慢中斷兩類中斷事件。 處理慢中斷前需保存所有寄存器的內(nèi)容,而快中斷處理僅要保存被常規(guī)C函數(shù)修改的寄存器;慢中斷處理時(shí),不屏蔽其他中斷信號(hào),而快中斷處理時(shí)會(huì)屏蔽所有其他中斷; 慢中斷處理完畢后,通常不立即返回被中斷
21、的進(jìn)程,而是進(jìn)入調(diào)度程序重新調(diào)度,調(diào)度結(jié)果未必是被中斷的進(jìn)程運(yùn)行(是搶先式調(diào)度)。而快中斷處理完畢后,通?;謴?fù)現(xiàn)場(chǎng)返回被中斷的進(jìn)程繼續(xù)執(zhí)行(是非搶先式調(diào)度)。,(2) 下半部分處理概述,中斷處理程序的特點(diǎn) 什么是下半部分處理? Top half Bottom half,中斷處理程序特點(diǎn),以異步方式運(yùn)行,可能會(huì)打斷關(guān)鍵代碼的執(zhí)行,甚至打斷其他中斷處理程序的執(zhí)行; 在屏蔽中斷狀態(tài)下運(yùn)行,最壞的情況會(huì)禁止所有中斷; 要對(duì)硬件進(jìn)行操作,有很高的時(shí)限要求;它在中斷上下文中運(yùn)行,故不能被阻塞 。,Linux各種下半部分機(jī)制,bottom half、 task queue、 tasklet、 work qu
22、eue、 Softirq。,Windows2003陷阱調(diào)度,2.2中斷技術(shù),3. Windows 2003中斷處理,Windows2003中斷請(qǐng)求級(jí)別,Windows 2003中斷屏蔽,系統(tǒng)服務(wù)調(diào)度(1),A0,SUB0,SUB1,SUBi,SUBn,A1,Ai,An,A0,A1,Ai,An,系統(tǒng)調(diào)用的處理過(guò)程,System Call,用戶程序,系統(tǒng)調(diào)用處理子程序,取系統(tǒng)功能號(hào) 找入口地址表 相應(yīng)入口地址,結(jié)束處理 恢復(fù)現(xiàn)場(chǎng),保護(hù)CPU現(xiàn)場(chǎng),自陷指令,系統(tǒng)調(diào)用陷入機(jī)構(gòu),入口地址表,系統(tǒng)服務(wù)調(diào)度(2),61,第二章 處理器管理,2.1 中央處理器 2.2 中斷技術(shù) 2.3 進(jìn)程及其實(shí)現(xiàn) 2.4
23、線程及其實(shí)現(xiàn) 2.5 Linux進(jìn)程和線程 2.6 Windows 2003進(jìn)程和線程 2.7 處理器調(diào)度 2.8 處理器調(diào)度算法 2.9 Linux調(diào)度算法 2.10 Windows 2003調(diào)度算法,本主題教學(xué)目標(biāo),掌握進(jìn)程的概念,可再入過(guò)程 掌握進(jìn)程的狀態(tài)、進(jìn)程的掛起,以及隊(duì)列實(shí)現(xiàn)模型 掌握操作系統(tǒng)的控制結(jié)構(gòu) 掌握進(jìn)程描述與控制的數(shù)據(jù)結(jié)構(gòu) 掌握處理機(jī)模式的概念 掌握進(jìn)程創(chuàng)建、模式切換、進(jìn)程切換、進(jìn)程隊(duì)列、進(jìn)程原語(yǔ)等進(jìn)程實(shí)現(xiàn)的原理 了解操作系統(tǒng)的執(zhí)行模型 了解SVR4的進(jìn)程管理,2.3 進(jìn)程及其實(shí)現(xiàn),進(jìn)程的概念 進(jìn)程的狀態(tài)和轉(zhuǎn)換 進(jìn)程的描述和組成 進(jìn)程控制和管理,Major Require
24、ments of an OS,Interleave the execution of several processes to maximize processor utilization while providing reasonable response time Allocate resources to processes Support interprocess communication(IPC) and user creation of processes,1. 進(jìn)程的概念,Process,Also called a task Execution of an individua
25、l program Can be traced list the sequence of instructions that execute,Process Definition,進(jìn)程是一個(gè)具有一定獨(dú)立功能的程序關(guān)于某個(gè)數(shù)據(jù)集合的一次運(yùn)行活動(dòng) A process is a program in execution, including: Process id and Data structure for process management and execution Code: program in memory Data: data in memory and its values Reg
26、ister values Program status word,Process Definition,Processi: (Pi, Ci, Di, Ri, Pswi) Program(data) Program(data) in memory (P1, C1, D1, R1, Psw1) and (P2, C2, D2, R2, Psw2) C1 and C2(different program) , but D1 and D2(different data) C1 and C2(different program) , but D1 and D2(same data) C1 and C2(
27、same program), but D1 and D2(different data) C1 and C2(same program), but D1 and D2(same data) (P1, C1, D1, R1, Psw1) and (P2, C2, D1, R2, Psw2) Concurrent programming(in fact, only share some data) (P1, C1, D1, R1, Psw1) and (P2, C1, D2, R2, Psw2) Share code(Reentrant program, Reentrant Procedure),
28、Process States Two-State Process Model Three-State Process Model Five-State Process Model Process Suspend,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Two-State Process Model,Process may be in one of two states Running Not-running,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Not-Running Process in a Queue,Process Creation,Submission of a batch job User logs on Cre
29、ated to provide a service such as printing Process creates another process,Process Termination,Batch job issues Halt instruction User logs off Quit an application Error and fault conditions,Reasons for Process Termination,Normal completion Time limit exceeded Memory unavailable Bounds violation Prot
30、ection error example write to read-only file Arithmetic error Time overrun process waited longer than a specified maximum for an event,Reasons for Process Termination,I/O failure Invalid instruction happens when try to execute data Privileged instruction Data misuse Operating system intervention suc
31、h as when deadlock occurs Parent terminates so child processes terminate Parent request,Process States Two-State Process Model Three-State Process Model Five-State Process Model Process Suspend,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Three-State Process Model,Not-running(Ready ) ready to execute Blocked(Waiting ) waiting for I
32、/O Dispatcher cannot select the blocked process,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Process State: Three States,Running, Ready, and Blocked(Wait),Process State: Three States,運(yùn)行態(tài)等待態(tài):等待使用資源;等待外設(shè)傳輸;等待人工干預(yù)/信號(hào) 等待態(tài)就緒態(tài):資源得到滿足;外設(shè)傳輸結(jié)束;人工干預(yù)/信號(hào)完成 運(yùn)行態(tài)就緒態(tài):運(yùn)行時(shí)間到;出現(xiàn)有更高優(yōu)先權(quán)進(jìn)程 就緒態(tài)運(yùn)行態(tài):CPU空閑時(shí)選擇一個(gè)就緒進(jìn)程,Process States Process Two-State Process M
33、odel Three-State Process Model Five-State Process Model Process Suspend,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Five-State Process Model,Running Ready Blocked New Exit,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Five-State Process Model,Process State: Five States,NULL新建態(tài):執(zhí)行一個(gè)程序/創(chuàng)建一個(gè)子進(jìn)程 新建態(tài)就緒態(tài):當(dāng)OS完成了進(jìn)程創(chuàng)建的必要操作,且當(dāng)前系統(tǒng)的性能和虛擬內(nèi)存的容量均允許 運(yùn)行態(tài)終止態(tài):當(dāng)一個(gè)進(jìn)程到達(dá)了自然結(jié)束點(diǎn),或出現(xiàn)了無(wú)法克服的
34、錯(cuò)誤,或被操作系統(tǒng)所終結(jié),或被其他有終止權(quán)的進(jìn)程所終結(jié) 終止態(tài)NULL:完成善后操作 就緒態(tài)終止態(tài):未在狀態(tài)轉(zhuǎn)換圖中顯示,但某些操作系統(tǒng)允許父進(jìn)程終結(jié)子進(jìn)程 等待態(tài)終止態(tài):未在狀態(tài)轉(zhuǎn)換圖中顯示,但某些操作系統(tǒng)允許父進(jìn)程終結(jié)子進(jìn)程,Using Two Queues,89,事件1 發(fā)生,事件2 發(fā)生,事件n 發(fā)生,允許進(jìn)入,分派,釋放,分派,分派,Yet another queuing model:每個(gè)優(yōu)先級(jí)對(duì)應(yīng)一個(gè)就緒隊(duì)列,90,有掛起態(tài)的排隊(duì)模型, 每個(gè)事件一個(gè)阻塞隊(duì)列,91,Representation of Process Scheduling,Process States Process
35、 Two-State Process Model Three-State Process Model Five-State Process Model Process Suspend,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Suspended Processes,Processor is faster than I/O so all processes could be waiting for I/O Swap these processes to disk to free up more memory Blocked state becomes suspend state when swapped to d
36、isk Two new states Blocked, suspend Ready, suspend,2. 進(jìn)程的狀態(tài)和轉(zhuǎn)換,Process State: Suspended,由于進(jìn)程的不斷創(chuàng)建,系統(tǒng)的資源已經(jīng)不能滿足進(jìn)程運(yùn)行的要求,這個(gè)時(shí)候就必須把某些進(jìn)程掛起(suspend),對(duì)換到磁盤鏡像區(qū)中,暫時(shí)不參與進(jìn)程調(diào)度,起到平滑系統(tǒng)操作負(fù)荷的目的,One Suspend State,Two Suspend States,97,改進(jìn):每個(gè)優(yōu)先級(jí)一就緒個(gè)隊(duì)列,Process State: Suspended,一個(gè)掛起進(jìn)程等同于不在主存的進(jìn)程,它將不參與進(jìn)程調(diào)度直到它們被對(duì)換進(jìn)主存。它具有如下特征:
37、 該進(jìn)程不能立即被執(zhí)行 掛起進(jìn)程可能會(huì)等待一個(gè)事件,但所等待的事件是獨(dú)立于掛起條件的,事件結(jié)束并不能導(dǎo)致進(jìn)程具備執(zhí)行條件 進(jìn)程進(jìn)入掛起狀態(tài)是由于操作系統(tǒng)、父進(jìn)程或進(jìn)程本身阻止它的運(yùn)行 結(jié)束進(jìn)程掛起狀態(tài)的命令只能通過(guò)操作系統(tǒng)或父進(jìn)程發(fā)出,Process State: Suspended,等待態(tài)掛起等待態(tài):如果當(dāng)前不存在就緒進(jìn)程,那么至少有一個(gè)等待態(tài)進(jìn)程將被對(duì)換出去成為掛起等待態(tài);操作系統(tǒng)根據(jù)當(dāng)前資源狀況和性能要求,也可以決定把等待態(tài)進(jìn)程將被對(duì)換出去成為掛起等待態(tài) 掛起等待態(tài)掛起就緒態(tài):引起進(jìn)程等待的事件發(fā)生之后,相應(yīng)的掛起等待態(tài)進(jìn)程將轉(zhuǎn)換為掛起就緒態(tài) 就緒態(tài)掛起就緒態(tài):操作系統(tǒng)根據(jù)當(dāng)前資源狀況和
38、性能要求,也可以決定把就緒態(tài)進(jìn)程將被對(duì)換出去成為掛起就緒態(tài),Process State: Suspended,運(yùn)行態(tài)掛起就緒態(tài):當(dāng)一個(gè)具有較高優(yōu)先級(jí)的掛起等待態(tài)進(jìn)程的等待事件結(jié)束后,它需要搶占了CPU,而此時(shí)主存空間有不夠,從而可能導(dǎo)致正在運(yùn)行的進(jìn)程轉(zhuǎn)化為掛起就緒態(tài)。另外處于運(yùn)行態(tài)的進(jìn)程也可以自己掛起自己 新建態(tài)掛起就緒態(tài):考慮到系統(tǒng)當(dāng)前資源狀況和性能要求,可以決定新建的進(jìn)程將被對(duì)換出去成為掛起就緒態(tài),Process State: Suspended,掛起就緒態(tài)就緒態(tài):當(dāng)內(nèi)存中沒(méi)有就緒態(tài)進(jìn)程,或者掛起就緒態(tài)進(jìn)程具有比就緒態(tài)進(jìn)程更高的優(yōu)先級(jí),系統(tǒng)將把掛起就緒態(tài)進(jìn)程轉(zhuǎn)換成就緒態(tài) 掛起等待態(tài)等待態(tài):
39、當(dāng)一個(gè)進(jìn)程等待一個(gè)事件時(shí),原則上時(shí)不需要把它調(diào)入內(nèi)存的。但是在下面一種情況下,這一狀態(tài)變化時(shí)可能的。當(dāng)一個(gè)進(jìn)程退出后,主存已經(jīng)有了一大塊自由空間,而某個(gè)掛起等待態(tài)進(jìn)程具有較高的優(yōu)先級(jí)并且操作系統(tǒng)已經(jīng)得知導(dǎo)致它阻塞的事件即將結(jié)束,此時(shí)便發(fā)生了這一狀態(tài)變化,Reasons for Process Suspension,Process Description and Control,Process States Process Description Processes and Resources OS Control Structures Process Control Structures Pr
40、ocess Control Examples: Process,3. 進(jìn)程的描述和組成,Process Description,Process Description and Control,Process States Process Description Processes and Resources OS Control Structures Process Control Structures Process Control Examples: Process,3. 進(jìn)程的描述和組成,Operating System Control Structures,Information ab
41、out the current status of each process and resource Tables are constructed for each entity the operating system manages,Memory Tables,Allocation of main memory to processes Allocation of secondary memory to processes Protection attributes for access to shared memory regions Information needed to man
42、age virtual memory,I/O Tables,I/O device is available or assigned Status of I/O operation Location in main memory being used as the source or destination of the I/O transfer,File Tables,Existence of files Location on secondary memory Current Status Attributes Sometimes this information is maintained
43、 by a file-management system,Process Table,Where process is located Attributes necessary for its management Process ID Process state Location in memory,OS Control Structure,Process Description and Control,Process States Process Description Processes and Resources OS Control Structures Process Contro
44、l Structures Process Location Process Attributes Process Control Examples: Process,3. 進(jìn)程的描述和組成,Process Location,Process includes set of programs and data Programs: the program to be executed User Data: the modifiable part of the user space, include program data, user stack, and program that may be m
45、odified System Stack: used to store parameters and calling addresses for system call Process Control Block (PCB): Collection of attributes Process image Collection of program, data, stack, and attributes (PCB),114,進(jìn)程映像 進(jìn)程控制塊:存儲(chǔ)進(jìn)程標(biāo)志信息、現(xiàn)場(chǎng)信息和控制信息。 進(jìn)程程序塊:被執(zhí)行的程序,規(guī)定進(jìn)程一次運(yùn)行應(yīng)完成的功能。通常它是純代碼,作為一種系統(tǒng)資源可被多個(gè)進(jìn)程共享。 進(jìn)
46、程核心棧:每個(gè)進(jìn)程捆綁一個(gè),進(jìn)程在核心態(tài)下工作時(shí)使用,用來(lái)保存中斷/異常現(xiàn)場(chǎng),及執(zhí)行函數(shù)調(diào)用的參數(shù)和返回地址,系統(tǒng)調(diào)用的參數(shù)和返回地址等。 進(jìn)程數(shù)據(jù)塊:即進(jìn)程私有地址空間,存放各種私有數(shù)據(jù),用戶棧也在數(shù)據(jù)塊中開辟,用于函數(shù)調(diào)用時(shí)存放棧幀、局部變量等參數(shù),包括程序數(shù)據(jù)、用戶棧和可修改的程序。,3. 進(jìn)程的描述和組成,115,程序塊,數(shù)據(jù)塊,PCB,進(jìn)程映像,核心棧,Process Description and Control,Process States Process Description Processes and Resources OS Control Structures Proc
47、ess Control Structures Process Location Process Attributes Process Control Examples: Process,3. 進(jìn)程的描述和組成,Process Control Block,Process identification Identifiers Numeric identifiers that may be stored with the process control block include Identifier of this process Identifier of the process that cr
48、eated this process (parent process) User identifier,Process Control Block,Processor State Information User-Visible Registers A user-visible register is one that may be referenced by means of the machine language that the processor executes. Typically, there are from 8 to 32 of these registers, altho
49、ugh some RISC implementations have over 100.,Process Control Block,Processor State Information Control and Status Registers These are a variety of processor registers that are employed to control the operation of the processor. These include Program counter: Contains the address of the next instruct
50、ion to be fetched Condition codes: Result of the most recent arithmetic or logical operation (e.g., sign, zero, carry, equal, overflow) Status information: Includes interrupt enabled/disabled flags, execution mode,Process Control Block,Processor State Information Stack Pointers Each process has one
51、or more last-in-first-out (LIFO) system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls. The stack pointer points to the top of the stack.,Process Control Block,Process Control Information Scheduling and State Information: This is i
52、nformation that is needed by the operating system to perform its scheduling function. Typical items of information: Process state Priority Scheduling-related information: This will depend on the scheduling algorithm used Event: Identity of event the process is awaiting before it can be resumed,Proce
53、ss Control Block,Process Control Information Data Structuring A process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-crea
54、ted) relationship with another process. The process control block may contain pointers to other processes to support these structures.,Process Control Block,Process Control Information InterProcess Communication Various flags, signals, and messages may be associated with communication between two in
55、dependent processes. Some or all of this information may be maintained in the process control block.,Process Control Block,Process Control Information Process Privileges Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed. I
56、n addition, privileges may apply to the use of system utilities and services.,Process Control Block,Process Control Information Memory Management This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process. Resource Ownership and Utilizat
57、ion Resources controlled by the process may be indicated, such as opened files. A history of utilization of the processor or other resources may also be included; this information may be needed by the scheduler.,Process List Stuctures,Processor State Information,Contents of processor registers User-
58、visible registers Control and status registers Stack pointers Program status word (PSW) contains status information Example: the EFLAGS register on Pentium machines,Pentium II EFLAGS Register,Process Context (進(jìn)程上下文),User-level context: include process program, process data, user stack Register conte
59、xt: include PSW, stack pointer, general-purpose register System-level context: include PCB, memory region table, kernel stack,Process States Process Description Process Control Modes of Execution Process Creation Process Switching Execution of the OS Summary Examples: Process,4. 進(jìn)程控制和管理,Modes of Execution,User mode Less-privileged mode User programs typically execute in this mode System mode, control mode, or kernel mode More-privileged mode Kernel of the operating system,4.進(jìn)程的控制和管理,Process States Process Description Process Control Modes of Executio
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年仁愛科普版選擇性必修2物理上冊(cè)月考試卷含答案
- 2025-2030年中國(guó)醫(yī)院后勤服務(wù)市場(chǎng)競(jìng)爭(zhēng)狀況及投資趨勢(shì)分析報(bào)告
- 2025-2030年中國(guó)醫(yī)用干式激光相機(jī)行業(yè)運(yùn)行動(dòng)態(tài)及前景趨勢(shì)預(yù)測(cè)報(bào)告
- 2024執(zhí)行項(xiàng)目經(jīng)理聘任合同協(xié)議書-智能家居系統(tǒng)研發(fā)3篇
- 2025-2030年中國(guó)制傘產(chǎn)業(yè)市場(chǎng)發(fā)展前景調(diào)研與投資策略分析報(bào)告
- 2024年重慶公共運(yùn)輸職業(yè)學(xué)院高職單招數(shù)學(xué)歷年參考題庫(kù)含答案解析
- 2025年滬科新版五年級(jí)語(yǔ)文上冊(cè)階段測(cè)試試卷
- 2025-2030年中國(guó)三氯異氰尿酸行業(yè)深度評(píng)估及投資風(fēng)險(xiǎn)評(píng)估報(bào)告
- 2025-2030年中國(guó)uv燈管市場(chǎng)規(guī)模分析及投資策略研究報(bào)告
- 二零二五年度影視作品個(gè)人表演傭金協(xié)議書3篇
- 2025年競(jìng)聘醫(yī)院內(nèi)科醫(yī)生崗位演講稿模版(3篇)
- 虛擬貨幣地址分析技術(shù)的研究-洞察分析
- 綠色供應(yīng)鏈管理制度內(nèi)容
- 心理學(xué)基礎(chǔ)知識(shí)考試參考題庫(kù)500題(含答案)
- 電力智慧檢修安全運(yùn)行三維可視化管理平臺(tái)建設(shè)方案
- 一年級(jí)數(shù)學(xué)(上)計(jì)算題專項(xiàng)練習(xí)集錦
- 消防安全應(yīng)急預(yù)案下載
- 《北航空氣動(dòng)力學(xué)》課件
- 附件:財(cái)政業(yè)務(wù)基礎(chǔ)數(shù)據(jù)規(guī)范(3.0版)
- 電商公司售后服務(wù)管理制度
- 火災(zāi)應(yīng)急處理課件
評(píng)論
0/150
提交評(píng)論