操作系统课件02

上传人:206****923 文档编号:47097211 上传时间:2018-06-29 格式:PDF 页数:36 大小:110.75KB
返回 下载 相关 举报
操作系统课件02_第1页
第1页 / 共36页
操作系统课件02_第2页
第2页 / 共36页
操作系统课件02_第3页
第3页 / 共36页
操作系统课件02_第4页
第4页 / 共36页
操作系统课件02_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《操作系统课件02》由会员分享,可在线阅读,更多相关《操作系统课件02(36页珍藏版)》请在金锄头文库上搜索。

1、Introduction to Operating Systems Lecture 2: Process and ThreadQIAN Weining Institute of Massive Computing East China Normal University28/02/08ossei.ecnu2OutlineMotivation: overview of a running programWhat is a process?: from a VM perspectiveState transition of a processProcess schedulingCollabora

2、ting processesThreads (vs. processes)Thread schedulingKernel and user mode threads28/02/08ossei.ecnu3Overview of a running programExecution sequence:1. Fetch instruction at PC (to IF)2. Decode3.Execute (possibly using registers)4.Write result to registers/memory5. PC usermode switch: kernel=user)4.

3、met other interrupts or system calls5. .6. reload state from PCB17. .28/02/08ossei.ecnu10Issues of multiprogrammingScheduling: multiplex in time to different processesAt most one active process on a CPU at a timeWhoWho? and How longHow long?Protection: allocate resources to processesAccess controlpr

4、ocess no.registersprocess counterprocess state.memory limitslist of open filesPCBPCB28/02/08ossei.ecnu11State transition: What? and When?newreadyrunningwaitingterminatedadmitted exitinterruptscheduler dispatch i/o or event completion i/o or event wait28/02/08ossei.ecnu12State transition: When?Proces

5、s creationProcess creationParent process creates children ones (tree of processes)Process terminationProcess terminationLast statement is executed and the process asks the OS to delete it (exit() orIts parent wants to terminate it (abort()maybe because of cascading terminationcascading termination28

6、/02/08ossei.ecnu13State transition: How?Process creationProcess creationConstruction of the new PCB (inexpensive)Setting up the mapping for address space (more expensive)Copy data from parent process (fork() in unix) (very expensive)exec() in unix after a fork() replace the memory space with a new p

7、rogram“copy on write” is much less expensive (to be visited later)Copy I/O state (medium expensive)28/02/08ossei.ecnu14State transition: How?Process terminationProcess terminationoutput data from child to parentOS deallocate resourcesProcess schedulingProcess schedulingLong-term scheduling (job sche

8、duling)Short-term scheduling (CPU scheduling)Medium-term schedulingProcess scheduling queuesJob queueReady queueDevice queues28/02/08ossei.ecnu15Process schedulingready queueCPUi/o queuei/o requesttime slice expiredfork()wait for an interruptI/Ochild executesinterrupt occurs28/02/08ossei.ecnu16Proce

9、ss schedulingLong-term schedulingLong-term schedulingwho should be brought into the ready queue (from job queue)Short-term schedulingShort-term schedulingwho should be executed on CPU next (from ready queue)Medium-term schedulingMedium-term scheduling (to be visited later)who should be swapped out/i

10、n?28/02/08ossei.ecnu17Collaborating processesWe may use multiple processes to collaborate on a task, but:with high creation/memory overheadrelatively high context-switch overheadneed additional communication mechanismsince address spaces are isolatedWe may use shared memory mappingshared memory mapp

11、ing or message message passingpassing28/02/08ossei.ecnu18Shared memory mappingtextdataheapstack.textdataheapstack.sharedshared28/02/08ossei.ecnu19Inter-process communication (IPC)WhyWhy?: communicate or synchronize between processesWhatWhat?: two operations:send(message)receive(message)HowHow?:estab

12、lish a communication linkcommunication linksend/receiveHow to implementHow to implement?physical vs. logical28/02/08ossei.ecnu20Threads: Why?Heavy weight process revisited: a thread a thread (lightweight process) + address space(lightweight process) + address spaceA single, sequential stream of exec

13、utionA single, sequential stream of execution in its own address spaceMulti-threading (multi-tasking)Multi-threading (multi-tasking): a single program with a number of different concurrentconcurrent activitiesSeparate concurrencyconcurrency (thread) problem from protectionprotection (address space)2

14、8/02/08ossei.ecnu21Thread: Why?Embedded systemsPCDB servers: thread poolsNetwork serversParallel programming28/02/08ossei.ecnu22registers, stackThread: What?single thread processcode, data, filesregisters, stackmulti-thread processcode, data, filesregisters, stackregisters, stack28/02/08ossei.ecnu23

15、Thread: What?State shared by all threads in a State shared by all threads in a process/address spaceprocess/address spacecontents of memory (global variables, heap)I/O stateState private to each threadState private to each threadCPU registers (and PC)Execution stack: for parameters, temporary variables, and return PCsStored in Thread Control Block (TCB)28/02/08ossei.ecnu24Process-thread relationship classificationembedded systems java os pilotmach, os/2, linux windows 9x windows nt (xp, vista, .) modern unix: solaris, hp-ux, .dos, early macintosht

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号