操作系统设计与实现(第二章).ppt
《操作系统设计与实现(第二章).ppt》由会员分享,可在线阅读,更多相关《操作系统设计与实现(第二章).ppt(113页珍藏版)》请在三一办公上搜索。
1、操作系统设计与实现,Chapter 2 Processes,*The importance of process in an operating system2.1 Introduction to processes*common Parallelism=Pseudoparallelism*It is the cpu rapid switching back and forth*multiprocessor is the real parallelism*people design a model,sequential processes 顺序进程,2.1.1 The process mode
2、l,Characters:*All the runnable software are organized into a number of sequential processes;(in this chapter we called it processes)*The process is an executing program;The process include the values of the all the program counter,registers,and variables;(进程包括程序计数器、寄存器和变量的当前值。)To these characters,it
3、 is easy to analysis the collection of the processes than keep track the rapid switch of CPU,Process-Program,Process is an executing program,it has program,input,output,and state.An example:scientist prepare the cake for his daughter.Recipe:/resipi/食谱*A Process is an activity of some kind,It has a p
4、rogram,input,output,and a state,A single processor may be shared among several processes,with some scheduling algorithm being used to determine when to stop work on one process and service a different one.,理解进程和程序的区别:CPU:计算机科学家程序1:烘制生日蛋糕的食谱数据:面粉、鸡蛋、糖和香草汁等对应的进程1:阅读食谱、取来各种原料以及烘制蛋糕的一系列动作的总和。事件:女儿被蜜蜂螫伤保
5、存进程1的当前状态:计算机科学家就记录下自己照着食谱做到哪儿了。程序2:急救手册数据:药物等对应的进程2:实施医疗救治(高优先级进程)当蜜蜂螫伤处理完之后,计算机科学家又回来做蛋糕,从他离开时的那一步继续做下去。,进程的创建,系统初始化(1)前台进程:同用户交互并替它们完成工作的哪些进程。(2)后台进程:守护进程,处理网页、打印之类活动的进程。2.正在运行的一个进程执行了创建进程的系统调用。3.用户请求创建一个新进程。在交互式系统中,用户可以通过键入命令启动程序。4.批处理作业的初始化 在操作系统认为有资源运行另一个作业时,它创建一个新的进程,并运行其输入队列中的一个作业。,进程的终止,正常退
6、出:多数进程由于完成了它们的工作而终止。出错退出(自愿):进程发现了严重错误。严重错误(非自愿):通常是由于程序中的错误所致。例如,执行了一条非法指令,引用了不存在的内存,或除数是零。被其它进程杀死:当一个进程终止时,由该进程所创建的所有进程也都立即被杀死。,Process hierarchies,Any OS,to support process,it must provide some way to create all the processes needed.Use fork()to create a new process,the father process can create
7、his child processes,0more,and later,the process tree may appeared.In Minix,the root is init,and it works in this way:read info,create terminal,start program,NFS,SMTP,WWW,FTP,Process States,进程之间经常需要交互、通信以及和其他进程同步。For Communication between processesexchange info among them,but,once more than one proce
8、sses lead to block*logically,it have to stop,it will.(wait our input)*logically,it should continue,but it stopped,now,the CPU may be occupied by another process.运行态(Running,在该时刻实际占用处理机)。就绪态(Ready,可运行,因为其它进程正在运行而暂时被挂起)。阻塞态(Blocked,除非某种外部事件发生,否则不能运行)。,2.1.2 Implementation of Processes,*Process Table(a
9、n array of structures)(进程表)each process is a record of this table,and each record include the state of the process,program counter,stack pointer,and allocation of memory.;thus,when the process is in ready state,all the info wont lose.In MINIX,the process management,memory management,and file managem
10、ent are each handled by separate modules within the system,so the process table is partitioned.Look at the pic:,Interrupt Vector(中断向量),An interruption,it relate to each kinds of I/O device(hardware),it contain the address of the interrupt service procedure.The interrupt procedure store the current v
11、ariables and info to stacks,and did some works related to its recover.Now,the pre process is stored,and the new one could continue.When it is finished,the old one could be recalled,and runs smoothly,just nothing had happened.Of course the interrupt must related to their priority.The real procedure i
12、s:,2.1.3 Threads(线程),1.Conceptto the traditional process,one process just has one control clue(控制流)and one program counter.In modern OS,more and more OS support the multi-control clue in a process,and we call these control clue threads.The real application of threads model from the application to sh
13、ow its importance to OS,多线程的应用(1),explorer netscape(网络浏览器)许多Web页面都包含有多幅很小的图像。site:the images folder lies D:siteimagesprocess:build up one connectionthreads:build up more connection 在浏览器内设立多个进程,同时请求传输多幅图像,可节省建立和释放链接的时间。To small size files,the connection-building needs more time than transporting.tran
14、smitting use.rar.zip than folder.,多线程的应用(2),网络蚂蚁(NetAnts)是从因特网下载文件的工具软件,设计特点如下:(A)支持HTTP和FTP协议,可同时下载1-5个文件;(B)可随时中止正在下载的任务,任务将自动保存当前状态;(C)支持拖放,可从浏览器中将链接拖入任务列表;(D)裁剪板自动监视,并可指定将捕获的文件类型;(E)捕获浏览器的动作,当用户在浏览器中单击链接时,网络蚂蚁将自动激活。,A,B,To A:when sever is busy,it will stopped,the writing will stopped.save the de
15、stination to.To B:when server is busy,other threads will still try.the writing wont stopped.use flashget netant,进程和线程的区别,允许在同一个进程环境中有多个执行流(线程),这些流在很大程度上相对独立,但共享相同的地址空间。进程用来集合资源,而线程是CPU中调度的实体。,To B:these threads share the same address spaceAnd these threads can write the information to the same place
16、,the same file.So the table will can be used to threads,then the threads can be restore、block、ready.Meaning:all the program can use the resources more efficiently,improved the OSs performance.,2.ProblemsTo different OS,the problems are different.1)OS dont know the existence of threadsThe control of
17、threads will by in user space.Then many threads packages are there.eg P-threads2)OS know the existence of threadsthe kernel will create the table to maintain the threads,threads table.,The difference of the two kind of OS,Conclusion:Get them together,adopt them two.,3)The new problems!Parent-process
18、&child-processparents process has many child threads,then how about the child-process!Multi processes share the data-structureone thread is closing a file,while the file is be reading by another thread.one thread is apply the memory,but now,switch happened,another threads will reapply.!Error reports
19、in Unix,the returned error value is stored in a variable,when one is stored a value there,then another cleared the value,and write a new value to there,then?,2.2 Inter Processes Communication(IPC),CONTENTS:How a process to send messages to another one;We must make sure the processes cant effect each
20、 other when they are visiting the critical area;When the reliable relations are there,how to design their proper order.,2.2.1 Race condition(竞争条件),To Process A:read In,write 7 to Next-free-slot(local);Interruption:A blocked,and B came in;B read In,got 7,then save name to slot7;In+1=8,B will think hi
21、s job is finished;A came back,and read local next-free-slot,save name to slot 7,and next-free-slot+1=8,save 8 to In.B will never be print.,打印机假脱机系统,2.2.2 Critical region-Critical section,Mutual exclusion(互斥):any share resource(memory、file)may happen the similar errors(spooler),we have to take this m
22、easure to prevent the race.,When the race will happen?If the race happens between two processes,they wont race from the beginning to the end.Only when they visit the same memory area or the same file,the race will happen.Here,if a program segment could visit the shared memory,we called the program s
23、egment critical region or critical section.(临界区或临界段),临界区的定义:,假如两个或更多的进程需要访问一个不可共享的资源(打印机),在执行过程中,每个进程都给该I/O设备发送命令,接受状态信息,发送数据,接收数据。我们把这类资源称作临界资源,使用临界资源的那一部分程序称作成程序的临界区。一次只允许有一个程序在临界区中。,互斥的定义:用某种手段,避免多个进程访问同一个临界区的操作叫做互斥。,进程的交互关系:可以按照相互感知的程度来分类,互斥,指多个进程不能同时使用同一个共享资源;死锁,指多个进程互不相让,都得不到足够的资源;饥饿,指一个进程一直得不
24、到资源(其他进程可能轮流占用资源),相互感知的程度,交互关系,一个进程对其他进程,的影响,潜在的控制问题,相互不感知,(,完全不,了解其它进程的存,在,),竞争,(competition),一个进程的操作对其,他进程的结果无影响,互斥,死锁(可释放的,资源),饥饿,间接感知,(,双方都与,第三方交互,如共享,资源,),通过共享进行协作,一个进程的结果依赖,于从其他进程获得的,信息,互斥,死锁(可释放的,资源),饥饿,数据一,致性,直接感知,(,双方直接,交互,如通信,),通过通信进行协作,一个进程的结果依赖,于从其他进程获得的,信息,死锁,饥饿,How to solve it?if we co
25、uld settle the processes very well,to avoid the processes visit the shared memory at the same time,then the race will be solved.To any good plans,we should make sure that:!Any two processes cant stayed in the critical area at the same time;!We shouldnt do any supposition to CPUs speed and number;!Th
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 设计 实现 第二

链接地址:https://www.31ppt.com/p-2346552.html