您好,欢迎访问三七文档
Chapter4:Processes进程OS管理资源为用户提供服务,为用户提供服务实际上就是有程序在运行,这些程序都会占用一定的资源,这些资源如何表述?OS使用进程来表述每一个运行的程序及其所占用的资源(计算机),包括程序计数器、寄存器、内存、文件、I/O等等,每一个进程看成是一个计算机进程是OS的一个关键概念,也是OS处理机管理的关键部分进程与程序的区别,进程是执行中的程序及其所需要的资源抽象,是动态的,程序是静止的(想想菜谱和对着菜谱做菜,或者一本书与读这本书)Chapter4:Processes进程ProcessConcept进程概念ProcessScheduling进程调度OperationonProcesses进程的操作CooperatingProcesses协作进程InterprocessCommunication进程间通讯SystemAbstraction:ProcessesAprocessisasystemabstraction:illusionofbeingtheonlyjobinthesystemhardware:computeroperatingsystem:processuser:runapplicationcreate,killprocesses,inter-processcomm.MultiplexingresourcesProcesses:MechanismandPolicyMechanism(机制):Creation,destruction,suspension,contextswitch(上下文),signaling(信号),IPC(进程之间通信),etc.Policy(政策):Minorpolicyquestions(最小集合问题)Whocancreate/destroy/suspendprocesses?Howmanyactiveprocessescaneachuserhave?Majorpolicyquestionthatwewillconcentrateon(最大集合)Howtosharesystemresourcesbetweenmultipleprocesses?TypicallybrokenintoanumberoforthogonalpoliciesforindividualresourcesuchasCPU,memory,anddisk.ProcessConceptAnoperatingsystemexecutesavarietyofprograms:Time-sharedsystems–userprogramsortasksBatchsystem–jobsTextbookusesthetermsjobandprocess,taskalmostinterchangeably.Process–aprograminexecution;processexecutionmustprogressinsequentialfashion.进程-在执行中的程序;进程的执行必须以顺序方式进行Aprocessincludes:programcounter程序计数器stack栈datasection数据部分ProcessConcept(cont.)1.Eachvariablemustbeassignedastorageclass2.Global(static)variablesAllocatedinglobalsregionatcompile-time3.MethodlocalvariablesandparametersAllocatedynamicallyonstack4.Dynamicallycreatedobjects(usingnew)AllocatefromheapObjectslivebeyondinvocationofamethodGarbagecollectedwhennolonger“live”TheProcessProcess=systemabstractionforthesetofresourcesrequiredforexecutingaprogram=arunninginstanceofaprogram=memoryimage+registers’content(+I/Ostate)进程就是执行一个程序所需要的资源集的系统抽象一个程序的一个运行实例内存映像+寄存器+I/OProcessinmemory代码、当前活动(PC、register)全局变量临时数据(函数参数、返回值、局部变量)进程运行过程中动态分配的内存ProcessStateAsaprocessexecutes,itchangesstate进程执行时,改变状态new:Theprocessisbeingcreated.新建:在创建进程running:Instructionsarebeingexecuted.运行:指令在执行waiting:Theprocessiswaitingforsomeeventtooccur.等待:进程等待某些事件发生ready:Theprocessiswaitingtobeassignedtoaprocessor.就绪:进程等待分配处理器terminated:Theprocesshasfinishedexecution.终止:进程执行完毕DiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessStateDiagramofProcessState记住、理解这个图一个进程处于new和terminated状态只有一次,处于其他状态可能会有多次ProcessStateNew→Ready:OS接纳新状态进程为就绪进程;Ready→Running:OS只能从就绪进程中选一个进程执行;Running→Exit:执行状态的进程执行完毕,或被取消,则转换为退出状态;Running→Ready:分时系统中,时间片用完,或优先级高的进程到来,将终止优先级低的进程的执行;Running→Blocked:执行进程需要等待某外部事件发生。通常因进程需要的系统调用不能立即完成,而阻塞;Blocked→Ready:当阻塞进程等待的事件发生,就转换为就绪状态Ready→Exit:某些系统允许父进程在任何情况下终止其子进程,若一个父进程终止,其子孙进程都必须终止;Processstate(cont.)QuestionSupposetherearetwoprocessesinthesystem,onewordprocessingprocessiswaitingfortheuser’sinput,theotherisadataprocessingtableprocesswhichiscalculating.Tellwhichstateeachofthetwoprocessesisin.ProcessControlBlock(PCB)TheOSmanageinformationforeachprocessineachprocesstable(软件的角度是一个数据结构)Informationassociatedwitheachprocess.同进程有关的信息Processstate进程状态Programcounter程序计数器CPUregistersCPU寄存器CPUschedulinginformationCPU调度信息Memory-managementinformation内存管理信息Accountinginformation计账信息I/OstatusinformationI/O状态信息ProcessControlBlock(PCB)CasestudyLinuxPCBCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessCPUSwitchFromProcesstoProcessProcessorAbstraction:ThreadsAthreadisaprocessorabstraction(一个线程就是一个处理器的抽象):illusionofhaving1processorperexecutioncontexthardware:processoroperatingsystem:threadapplication:executioncontextcreate,kill,synch.contextswitchProcessSchedulingQueues进程调度队列Jobqueue–setofallprocessesinthesystem.作业队列-在系统中的所有进程的集合Readyqueue–setofallprocessesresidinginmainmemory,readyandwaitingtoexecute.就绪队列-在主内存中的,就绪并等待执行的所有进程的集合Devicequeues–setofprocesseswaitingforanI/Odevice.设备队列-等待某一I/O设备的进程队列Processmigrationbetweenthevariousqueues.在各种队列之间进程的迁移ReadyQueueAndVariousI/ODeviceQueuesRepresentationofProcessSchedulingSchedulersLong-termscheduler(orjobscheduler)–selectswhichprocessesshouldbebroughtintothereadyqueue.长程调度(或作业调度)-选择可以进入就绪队列的进程Short-termscheduler(orCPUscheduler)–selectswhichprocessshouldbeexecutednextandallocatesCPU.短程调度(或CPU调度)-选择可被下一个执行并分配CPU的进程AdditionofMediumTermSchedulingSchedulers(Cont.)Short-termschedulerisinvokedveryfrequently(milliseconds)(mustbefast).短程调度切换频率高Long-termschedulerisinvokedveryinfrequently(seconds,minutes)(maybeslow).长程调度不快Thelong-termschedulercontrolsthedegreeofmultiprogramming.长程调度控制了多道程序的“道”Processescanbedescribedaseither:进程类型:I/O-boundprocess–spendsmoretimedoingI/Othancomputations,manyshortCPUbursts.I/O型进程-花费I/O时间多于计算,许多短CPU处理CPU-boundprocess–spendsmoretimedoingcomputations;fewverylongCPUbursts
本文标题:操作系统第4章
链接地址:https://www.777doc.com/doc-5473809 .html