操作系统最经典三张纸.doc_第1页
操作系统最经典三张纸.doc_第2页
操作系统最经典三张纸.doc_第3页
操作系统最经典三张纸.doc_第4页
操作系统最经典三张纸.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

进程:生产者-消费者问题(指利用了n-1个单元)shared data#define BUFFER_SIZE 10typedef struct . . . item;item bufferBUFFER_SIZE;int in = 0;int out = 0;item nextProduced; / local variablewhile (1) /* produce an item in nextProduced */while (in + 1) % BUFFER_SIZE) = out);bufferin = nextProduced;in = (in + 1) % BUFFER_SIZE;item nextConsumed; / local variablewhile (1) while (in = out); / buffer is emptynextConsumed = bufferout;out = (out + 1) % BUFFER_SIZE;/* consume the item in nextConsumed */调度队列的种类:1. job queue set of all processes in the system2. ready queue set of all processes residing in main memory, ready and waiting to executegenerally stored as a linked list3. device queues set of processes waiting for a particular I/O device, eg. a tape driver, a disk进程状态:1. new: being created2. running: instructions are being executed3. waiting: waiting for some event to occur4. ready: waiting to be assigned to a processor5. terminated: has finished execution调度器scheduler分类:long-term scheduler (or job scheduler) selects which processes should be loaded for executionshort-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU进程同步种类:1. blocking(synchronous) versus nonblocking (asynchronous)2. blocking send: the sending process is blocked until the message is received by the receiving process or by the mailbox3. nonblocking send: the sending process sends the message, and resumes operation4. blocking receive: the receiver blocks until a message is available5. nonblocking receive: the receiver retrieves either a valid message or a null, and resumes operationFCB的内容:1. Process state2. Program counter3. CPU registers4. CPU scheduling information5. Memory-management information6. Accounting information7. I/O status information8. page table or relocation register and limit register9. file open tableCPU调度算法1. FCFS:等待时间不稳定,响应时间不稳定。特点:easy to understand, easy to implement (an FIFO queue), large variance of waiting/response time. convoy effect. nonpreemptive, bad for time-sharing system2. SJF:分为preemptive & nonpreemptive.平均等待时间最短。最优但不实际的调度,是其他算法的判定标准。3. Priority scheduling:分为preemptive & nonpreemptive. 存在饥饿的问题,可以通过aging的方法来弥补。4. Round Robin: q large FIFO;q small q相对于切换上下文的时间而言不许足够长,否则将导致系统开销过大。time quantum/slice用完后,被抢占并插入就绪队列末尾,如果这个进程结束的时候有新进程产生,则挂在该进程的前面。假定就绪队列中有n个进程、时间量为q, 则每个进程每次得到1/n的、不超过q单位的成块CPU时间,没有任何一个进程的等待时间会超过(n-1)*q单位。RR的平均周转时间比SJF长,但响应时间要短一些。同步信号和异步信号:synchronous signalsan illegal memory access, a division by zerodelivered to the same process that cause the signalasynchronous signalsa user keystroke (Ctrl-C), a timer expirationtypically sent to another process线程池:Why the thread pools?1. avoid creation and termination overhead, so that it is faster to service a request2. put bound on number of threads, thus limit CPU and memory usageconsiderationsnumber of CPUsamount of physical memoryexpected number of concurrent requestsMany to one:many user-level threads mapped to single kernel threadthread management is done in user space,used on systems that do not support kernel threadsdrawbacks:bad blockingbad ,utilization of multiprocessorsone to one:each user-level thread maps to a kernel thread:more concurrency than many-to-one,support multiprocessorsdrawback:overhead of creating kernel threadsexamples:Windows 95/98/NT/2000,OS/2many to many:multiplexes many user level threads to a smaller or equal number of kernel threadsallows the programmer to create a sufficient number of user threadsavoid bad blocking, support multiprocessorsExamples:Solaris 2,Windows NT/2000 with the ThreadFiber package用户线程和内核线程User threads:supported above the kernelimplemented by a thread library at the user levelthe library support thread creation, scheduling, management with no support from the kernel(on a single thread kernel) any user-level thread performs a blocking system call blocks the whole processKernel threads:supported directly by the operating system: the kernel performs thread creation, scheduling, and management in kernel spaceslower to create and manage than user threadsindependent block among threadsgood support for multiprocessors线程:线程的终止:thread cancellation target thread: the thread to be cancelled asynchronous cancellation: one thread immediately terminates the target thread,may be cancelled in the middle of updating data shared with other threads,may not free a system-wide resource deferred cancellation: the target thread can periodically check if it should terminate (at so called cancellation points in Pthread)CPU调度的评判标准1. CPU utilization keep the CPU as busy as possible2. Throughput number of processes that complete their execution per time unit3. Turnaround time the interval from the time of submission of a process to the time of completion4. Waiting time amount of time a process has been waiting in the ready queue5. Response time amount of time it takes from when a request was submitted until the first responseCPU 调度:基于信号量的算法:把一个进程P屏蔽,从就绪队列转移到L上去。对于进程P调用执行wait(S)wait(S)S.value-;if (S.value 0)add this process to S.L;block;把一个进程P唤醒,从L转移到就绪队列中对于进程P调用执行signal(S)signal(S)S.value+;if (S.value m thrashingpolicy: if D m, then suspend one of the processes (and swap it out completely)the working-set strategy prevents thrashing while keeping the degree of multiprogramming as high as possible,it optimizes CPU utilization实现:approximate with interval timer + a reference bitExample: D = 10,000 references,timer interrupts about every 5000 references,keep in memory 2 bits for each page,whenever a timer interrupts, copy and sets the values of all reference bits to 0,if one of the bits in memory = 1 page in working set全局&局部页替换global replacement process selects a replacement frame from the set of all fra

温馨提示

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

评论

0/150

提交评论