operatingsystem《操作系統(tǒng)》ch03processes50課件_第1頁(yè)
operatingsystem《操作系統(tǒng)》ch03processes50課件_第2頁(yè)
operatingsystem《操作系統(tǒng)》ch03processes50課件_第3頁(yè)
operatingsystem《操作系統(tǒng)》ch03processes50課件_第4頁(yè)
operatingsystem《操作系統(tǒng)》ch03processes50課件_第5頁(yè)
已閱讀5頁(yè),還剩45頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Chapter 3: Processes第1頁(yè),共50頁(yè)。Chapter ObjectivesTo introduce the notion of a process - a program in execution, which forms the basis of all computation.To describe the various features of processes, including scheduling, creation and termination, and communication.To describe communication in client-

2、server systems.第2頁(yè),共50頁(yè)。Content OverviewProcess ConceptProcess SchedulingOperations on ProcessesCooperating ProcessesInterprocess CommunicationCommunication in Client-Server Systems第3頁(yè),共50頁(yè)。3.1 Process ConceptAn operating system executes a variety of programs:Batch system jobsTime-shared systems use

3、r programs or tasksTextbook uses the terms job and process almost interchangeablyProcess a program in execution; process execution must progress in sequential fashionA process includes:program counter Stackheapdata sectiontext section第4頁(yè),共50頁(yè)。Process in Memory第5頁(yè),共50頁(yè)。Process StateAs a process execu

4、tes, it changes statenew: The process is being createdready: The process is waiting to be assigned to a processorrunning: Instructions are being executedwaiting: The process is waiting for some event to occurterminated: The process has finished execution第6頁(yè),共50頁(yè)。Diagram of Process State第7頁(yè),共50頁(yè)。Proc

5、ess Control Block (PCB)Information associated with each processProcess stateProgram counterCPU registersCPU scheduling informationMemory-management informationAccounting informationI/O status information第8頁(yè),共50頁(yè)。Process Control Block (PCB)第9頁(yè),共50頁(yè)。CPU Switch From Process to Process第10頁(yè),共50頁(yè)。3.2 Proc

6、ess Scheduling The objective of multiprogramming is to have some process running at all times, to maximize CPU utilization. The objective of time sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running. To meet these objectives, the pr

7、ocess scheduler selects an available process (possibly from a set of several available processes) for program execution on the CPU. For a single-processor system, there will never be more than one running process. If there are more processes, the rest will have to wait until the CPU is free and can

8、be rescheduled.第11頁(yè),共50頁(yè)。Process Scheduling QueuesJob queue set of all processes in the systemReady queue set of all processes residing in main memory, ready and waiting to executeDevice queues set of processes waiting for an I/O deviceProcesses migrate among the various queues第12頁(yè),共50頁(yè)。Ready Queue

9、And Various I/O Device Queues第13頁(yè),共50頁(yè)。Representation of Process Scheduling第14頁(yè),共50頁(yè)。SchedulersLong-term scheduler (or job scheduler) selects which processes should be brought into the ready queueShort-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU第

10、15頁(yè),共50頁(yè)。Addition of Medium Term Scheduling第16頁(yè),共50頁(yè)。Schedulers (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 multiprogrammingProcesse

11、s can be described as either:I/O-bound process spends more time doing I/O than computations, many short CPU burstsCPU-bound process spends more time doing computations; few very long CPU bursts第17頁(yè),共50頁(yè)。Context SwitchWhen CPU switches to another process, the system must save the state of the old pro

12、cess and load the saved state for the new processContext-switch time is overhead; the system does no useful work while switchingTime dependent on hardware support第18頁(yè),共50頁(yè)。3.3 Operations on ProcessesProcess CreationParent process create children processes, which, in turn create other processes, form

13、ing a tree of processesResource sharingParent and children share all resourcesChildren share subset of parents resourcesParent and child share no resourcesExecutionParent and children execute concurrentlyParent waits until children terminate第19頁(yè),共50頁(yè)。Process Creation (Cont.)Address spaceChild duplic

14、ate of parentChild has a program loaded into itUNIX examplesfork system call creates new processexec system call used after a fork to replace the process memory space with a new program第20頁(yè),共50頁(yè)。Process Creation第21頁(yè),共50頁(yè)。C Program Forking Separate Processint main()pid_t pid; pid = fork(); /* fork an

15、other process */if (pid 0) /* error occurred */fprintf(stderr, Fork Failed);exit(-1);else if (pid = 0) /* child process */execlp(/bin/ls, ls, NULL);else /* parent process */wait (NULL); /* parent will wait for the child to complete */ printf (Child Complete);exit(0);第22頁(yè),共50頁(yè)。A tree of processes on

16、a typical Solaris第23頁(yè),共50頁(yè)。Process TerminationProcess executes last statement and asks the operating system to delete it (exit)Output data from child to parent (via wait)Process resources are deallocated by operating systemParent may terminate execution of children processes (abort) for:Child has ex

17、ceeded allocated resourcesTask assigned to child is no longer requiredIf parent is exitingSome operating system do not allow child to continue if its parent terminatesAll children terminated - cascading termination第24頁(yè),共50頁(yè)。3.4 InterProcess CommunicationIndependent process cannot affect or be affect

18、ed by the execution of another processCooperating process can affect or be affected by the execution of another processAdvantages of process cooperationInformation sharing Computation speed-upModularityConvenienceCooperating processes require an Interprocess communication (IPC) mechanism shared memo

19、ry / message passing第25頁(yè),共50頁(yè)。Communications Models Message Passing Shared Memory 第26頁(yè),共50頁(yè)。Shared-Memory Solution Producer-Consumer ProblemParadigm for cooperating processes, producer process produces information that is consumed by a consumer processunbounded-buffer places no practical limit on th

20、e size of the bufferbounded-buffer assumes that there is a fixed buffer size第27頁(yè),共50頁(yè)。Bounded-Buffer Shared data#define BUFFER_SIZE 10typedef struct . . . item;item bufferBUFFER_SIZE;int in = 0;int out = 0;Solution is correct, but can only use BUFFER_SIZE-1 elements第28頁(yè),共50頁(yè)。Bounded-Buffer Insert()

21、Methodwhile (true) /* Produce an item */ while (in = (in + 1) % BUFFER SIZE count) = out) ; /* do nothing - no free buffers */ bufferin = item; in = (in + 1) % BUFFER SIZE; 第29頁(yè),共50頁(yè)。Bounded Buffer Remove() Methodwhile (true) while (in = out) ; / do nothing - nothing to consume / remove an item from

22、 the buffer item = bufferout; out = (out + 1) % BUFFER SIZE;return item; 第30頁(yè),共50頁(yè)。Message-Passing SystemsMessage system processes communicate with each other without resorting to shared variablesIPC facility provides two operations:send(message) message size fixed or variable receive(message)If P a

23、nd 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)logical (e.g., logical properties)Direct or indirect communicationSynchronous or asynchronous communicat

24、ionAutomatic or explicit buffering第31頁(yè),共50頁(yè)。* 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 communicating processes?What is the capacity of a link?Is the size of a message that the link can ac

25、commodate fixed or variable?Is a link unidirectional or bi-directional?第32頁(yè),共50頁(yè)。Direct Communication- NamingProcesses 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 establishe

26、d automaticallyA link is associated with exactly one pair of communicating processesBetween each pair there exists exactly one linkThe link may be unidirectional, but is usually bi-directional第33頁(yè),共50頁(yè)。Indirect Communication- mailboxMessages are directed and received from mailboxes (also referred to

27、 as ports)Each mailbox has a unique idProcesses can communicate only if they share a mailboxProperties of communication linkLink established only if processes share a common mailboxA link may be associated with many processesEach pair of processes may share several communication linksLink may be uni

28、directional or bi-directional第34頁(yè),共50頁(yè)。Indirect CommunicationOperationscreate a new mailboxsend and receive messages through mailboxdestroy a mailboxPrimitives are defined as:send(A, message) send a message to mailbox Areceive(A, message) receive a message from mailbox A第35頁(yè),共50頁(yè)。Indirect Communicat

29、ionMailbox sharingP1, P2, and P3 share mailbox AP1, sends; P2 and P3 receiveWho gets the message?SolutionsAllow a link to be associated with at most two processesAllow only one process at a time to execute a receive operationAllow the system to select arbitrarily the receiver. Sender is notified who

30、 the receiver was.第36頁(yè),共50頁(yè)。SynchronizationMessage passing may be either blocking or non-blockingBlocking is considered synchronousBlocking send has the sender block until the message is receivedBlocking receive has the receiver block until a message is availableNon-blocking is considered asynchrono

31、usNon-blocking send has the sender send the message and continueNon-blocking receive has the receiver receive a valid message or null第37頁(yè),共50頁(yè)。BufferingQueue of messages attached to the link; implemented in one of three ways1.Zero capacity 0 messages Sender must wait for receiver 2.Bounded capacity finite length of n messages Sender must wait if link full3.Unbounded capacity infinite length Sender never waits第38頁(yè),共50頁(yè)。* 3.5 Examples of IPC SystemsPOSIX Shared Memory第39頁(yè),共50頁(yè)。Windows XP-LPC第

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論