《进程管理英》PPT课件.ppt

上传人:牧羊曲112 文档编号:5611276 上传时间:2023-08-02 格式:PPT 页数:38 大小:424.50KB
返回 下载 相关 举报
《进程管理英》PPT课件.ppt_第1页
第1页 / 共38页
《进程管理英》PPT课件.ppt_第2页
第2页 / 共38页
《进程管理英》PPT课件.ppt_第3页
第3页 / 共38页
《进程管理英》PPT课件.ppt_第4页
第4页 / 共38页
《进程管理英》PPT课件.ppt_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《《进程管理英》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《进程管理英》PPT课件.ppt(38页珍藏版)》请在三一办公上搜索。

1、Chapter 4:Processes,Process ConceptProcess SchedulingOperation on ProcessesCooperating ProcessesInterprocess Communication,Process Concept,An operating system executes a variety of programs:Batch system jobsTime-shared systems user programs or tasksTextbook uses the terms job and process almost inte

2、rchangeably.Process a program in executionA process includes:program counterstack data section,Process Concept,国内学术界较为一致的定义:进程是一个具有一定独立功能的程序,关于某个数据集合的一次可以并发执行的运行活动。From Wikipedia In computing,a process is an instance of a computer program that is being sequentially executed by a computer system that

3、 has the ability to run several computer programs concurrently.,Process Concept,A single computer processor executes one or more instructions at a time(per clock cycle),one after the other.To allow users to run several programs at once,single-processor computer systems can perform multiprogramming a

4、nd time-sharing.Using more than one physical processor on a computer,permits true simultaneous execution of more than one stream of instructions from different processes.Concurrency is the term generally used to refer to several independent processes sharing a single processorSimultaneously(or paral

5、lel)is used to refer to several processes,each with their own processor.,Process vs.Program,Dynamic/staticprocess is a program in execution,so it is dynamic,program is a passive collection of instuctions,so it is a static entity.Lify cycleprocess has a life cycle.It is an active entity in the sense

6、that it can be created,executed,and terminated during its lifetime.Program can exist forever.Structureprocess=program+data+PCBEach process is represented in the OS by a process control block(PCB),it contains all information associated with a specific process.,Process vs.Program,No one-to-one mapping

7、 between processes and programscan have mulitple processes of the same programone process can invoke multiple programsProcess is the basic unit of being scheduled and resource allocation from the viewpoint of OS,while program can not be run without process creation.Process can be executed concurrent

8、ly or simultaneously.,Process State,As a process executes,it changes statenew:The process is being created.running:Instructions are being executed.waiting:The process is waiting for some event to occur.ready:The process is waiting to be assigned to a processor.terminated:The process has finished exe

9、cution.,Diagram of Process State,admitted,I/O or event completion,scheduler dispatch,I/O or event wait,interrupt,exit,Process Control Block(PCB),Information associated with each process:Process state Program counterCPU registers CPU scheduling informationMemory-management informationAccounting infor

10、mationI/O status information,Process Control Block(PCB),CPU Switch From Process to Process,Chapter 4:Processes,Process ConceptProcess SchedulingOperation on ProcessesCooperating ProcessesInterprocess Communication,Process Scheduling,Process Scheduling QueuesJob queue set of all processes in the syst

11、em.Ready queue set of all processes residing in main memory,ready and waiting to execute.Device queues set of processes waiting for an I/O device.Process migration between the various queues.,Ready Queue And Various I/O Device Queues,Representation of Process Scheduling,Schedulers,Long-term schedule

12、r(or job scheduler)selects which processes should be brought into the ready queue.长程调度(或作业调度)Short-term scheduler(or CPU scheduler)selects which process should be executed next and allocates CPU.短程调度(或CPU调度),Addition of Medium Term Scheduling,Schedulers(Cont.),Short-term scheduler is invoked very fr

13、equently(milliseconds)(must be fast).调用频率高Long-term scheduler is invoked very infrequently(seconds,minutes)(may be slow).调用频率不高The long-term scheduler controls the degree of multiprogramming.长程调度控制了多道程序的“道数”Processes can be described as either:I/O-bound process spends more time doing I/O than comput

14、ations,many short CPU bursts.CPU-bound process spends more time doing computations;few very long CPU bursts.,Context Switch上下文切换,When CPU switches to another process,the system must save the state of the old process and load the saved state for the new process.Context-switch time is overhead;the sys

15、tem does no useful work while switching.Time dependent on hardware support.,Process Creation,Parent process creates children processes,which,in turn create other processes,forming a tree of processes.Resource sharingParent and children share all resources.Children share subset of parents resources.P

16、arent and child share no resources.ExecutionParent and children execute concurrently.Parent waits until children terminate.,Process Creation(Cont.),Address spaceChild duplicate of parent.Child has a program loaded into it.UNIX examplesfork system call creates new processexeclp system call used after

17、 a fork to replace the process memory space with a new program.,A Tree of Processes On A Typical UNIX System,Process Termination,Process executes last statement and asks the operating system to delete it(exit).Process resources are deallocated by operating system.Output data from child to parent(via

18、 wait).Parent may terminate execution of children processes Child has exceeded超过 allocated resources.Task assigned to child is no longer required.Parent is exiting.Operating system does not allow child to continue if its parent terminates.Cascading termination.级联终止,Cooperating Processes,Independent

19、process cannot affect or be affected by the execution of another process.Cooperating process can affect or be affected by the execution of another processAdvantages of process cooperationInformation sharingComputation speed-upModularityConvenience,Producer-Consumer Problem,Paradigm for cooperating p

20、rocesses,producer process produces information that is consumed by a consumer process.unbounded-buffer places no practical limit on the size of the buffer.无界缓冲没有对缓冲区大小的限制bounded-buffer assumes that there is a fixed buffer size.有界缓冲对缓冲区大小作了限定,Bounded-Buffer Shared-Memory Solution,Shared datavar n;typ

21、e item=;var buffer.array 0.n1 of item;in,out:0.n1;Producer process repeatproduce an item in nextpwhile in+1 mod n=out do no-op;buffer in:=nextp;in:=in+1 mod n;until false;,Bounded-Buffer(Cont.),Consumer process repeatwhile in=out do no-op;nextc:=buffer out;out:=out+1 mod n;consume the item in nextc

22、until false;Solution is correct,but can only fill up n1 buffer.,Threads,A thread(or lightweight process)is a basic unit of CPU utilization;it consists of:program counterregister setstack spaceA thread shares with its peer threads its:code sectiondata sectionoperating-system resourcescollectively kno

23、w as a task.整体作为一个任务,Threads(Cont.),In a multiple threaded task,while one server thread is blocked and waiting,a second thread in the same task can run.Cooperation of multiple threads in same job confers higher throughput and improved performance.Applications that require sharing a common buffer(i.e

24、.,producer-consumer)benefit from thread utilization.Threads provide a mechanism that allows sequential processes to make blocking system calls while also achieving parallelism.Kernel-supported threads(Mach and OS/2).User-level threads;supported above the kernel,via a set of library calls at the user

25、 level.Hybrid approach implements both user-level and kernel-supported threads(Solaris 2).混合处理实现用户级和内核支持线程,Interprocess Communication-IPC,Mechanism for processes to communicate and to synchronize their actions.Message system processes communicate with each other without resorting to shared variables

26、.IPC facility provides two operationssend(message)message size fixed or variablereceive(message)If P and Q wish to communicate,they need to:establish a communication link between themexchange messages via send/receiveImplementation of communication linkphysical(e.g.,shared memory,hardware bus)logica

27、l(e.g.,logical properties),Implementation Questions,How are links established?Can a link be associated with more than two processes?How many links can there be between every pair of communicating processes?What is the capacity of a link??Is the size of a message that the link can accommodate fixed o

28、r variable?Is a link unidirectional or bi-directional?,Direct Communication,Processes must name each other explicitly显式:send(P,message)send a message to process Preceive(Q,message)receive a message from process QProperties of communication linkLinks are established automatically.A link is associated

29、 with exactly one pair of communicating processes.Between each pair there exists exactly one link.The link may be unidirectional,but is usually bi-directional.,Indirect Communication,Messages are directed and received from mailboxes.Each mailbox has a unique id.Processes can communicate only if they

30、 share a mailbox.Properties of communication linkLink established only if processes share a common mailbox A link may be associated with many processes.Each pair of processes may share several communication links.Link may be unidirectional.al or bi-directional.Operationscreate a new mailboxsend and

31、receive messages through mailboxdestroy a mailbox,Types of Mailbox,Private Mailbox:owner-Receive other user-SendPublic Mailbox:owned by OSShared Mailbox:created by a process,the ownership and privilege be passed to other processes,Synchronization,Blocking send:sender blocked until the message is rec

32、eivedNonblocking send:send the message and resume operationBlocking receive:receiver blocked until a message is availableNonblocking receive:receiver retrieves either a valid message or null,Buffering,Queue of messages attached to the link;implemented in one of three ways.1.Zero capacity 0 messages Sender must wait for receiver.2.Bounded capacity finite length of n messages Sender must wait if link full.3.Unbounded capacity infinite length Sender never waits.,Exception Conditions Error Recovery,Process terminates 进程终止Lost messages 消息丢失Scrambled Messages 消息受损,Homework,P113 4.14.44.6,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号