进程管理英课件_第1页
进程管理英课件_第2页
进程管理英课件_第3页
进程管理英课件_第4页
进程管理英课件_第5页
已阅读5页,还剩33页未读, 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter 4: ProcessesProcess ConceptProcess SchedulingOperation on ProcessesCooperating ProcessesInterprocess CommunicationProcess ConceptAn operating system executes a variety of programs: Batch system jobsTime-shared systems user programs or tasksTextbook uses the terms job and process almost inter

2、changeably. Process a program in executionA process includes:program counterstack data sectionProcess 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 ConceptA 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

4、and 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

5、parallel) is used to refer to several processes, each with their own processor.Process vs. ProgramDynamic/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 t

6、he sense 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. ProgramNo

7、one-to-one mapping 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

8、executed concurrently or simultaneously.Process StateAs 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 p

9、rocess has finished execution.Diagram of Process Statenewreadyrunningwaiting/blockedterminatedadmittedI/O or event completionscheduler dispatchI/O or event waitinterruptexitProcess Control Block (PCB)Information associated with each process:Process state Program counterCPU registers CPU scheduling i

10、nformationMemory-management informationAccounting informationI/O status informationProcess Control Block (PCB)CPU Switch From Process to ProcessChapter 4: ProcessesProcess ConceptProcess SchedulingOperation on ProcessesCooperating ProcessesInterprocess CommunicationProcess SchedulingProcess Scheduli

11、ng QueuesJob queue set of all processes in the system. 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 QueuesRepresentation

12、of Process SchedulingSchedulersLong-term scheduler (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 SchedulingSche

13、dulers (Cont.)Short-term scheduler is invoked very frequently (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 ei

14、ther: I/O-bound process spends more time doing I/O than computations, 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 st

15、ate for the new process.Context-switch time is overhead; the system does no useful work while switching.Time dependent on hardware support.Process CreationParent process creates children processes, which, in turn create other processes, forming a tree of processes. Resource sharingParent and childre

16、n share all resources.Children share subset of parents resources.Parent 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 exampl

17、esfork system call creates new processexeclp system call used after a fork to replace the process memory space with a new program. A Tree of Processes On A Typical UNIX SystemProcess TerminationProcess executes last statement and asks the operating system to delete it (exit). Process resources are d

18、eallocated by operating system.Output data from child to parent (via 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 te

19、rminates. Cascading termination. 级联终止Cooperating ProcessesIndependent 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-upMod

20、ularityConvenienceProducer-Consumer ProblemParadigm for cooperating processes, 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.

21、有界缓冲对缓冲区大小作了限定Bounded-Buffer Shared-Memory SolutionShared datavar n;type 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 repeatwhil

22、e in = out do no-op;nextc := buffer out;out := out+1 mod n;consume the item in nextc until false;Solution is correct, but can only fill up n1 buffer.ThreadsA thread (or lightweight process) is a basic unit of CPU utilization; it consists of: program counterregister setstack spaceA thread shares with

23、 its peer threads its:code sectiondata sectionoperating-system resourcescollectively know 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 highe

24、r throughput and improved performance. Applications that require sharing a common buffer (i.e., 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 (M

25、ach and OS/2). User-level threads; supported above the kernel, via a set of library calls at the user level. Hybrid approach implements both user-level and kernel-supported threads (Solaris 2). 混合处理实现用户级和内核支持线程Interprocess Communication-IPCMechanism for processes to communicate and to synchronize th

26、eir actions.Message system processes communicate with each other without resorting to shared variables. 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 me

27、ssages via send/receiveImplementation of communication linkphysical (e.g., shared memory, hardware bus)logical (e.g., logical properties)Implementation QuestionsHow are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communi

28、cating processes? What is the capacity of a link? ?Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional? Direct CommunicationProcesses must name each other explicitly显式: send (P, message) send a message to process Preceive(Q, message) r

29、eceive a message from process QProperties of communication linkLinks are established automatically. A link is associated 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 Communicati

30、onMessages are directed and received from mailboxes.Each mailbox has a unique id. Processes can communicate only if they 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 s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论