zoukankan      html  css  js  c++  java
  • 现代操作系统期末复习

    答案仅供参考,不保证全部正确

    第一章 引论

    1. What are the two main functions of an operating system?

    1.为应用程序(程序员)提供资源集的清晰抽象
    2.管理硬件资源
    

    9. There are several design goals in building an operating system, for example, resource
    utilization, timeliness, robustness, and so on. Give an example of two design goals that
    may contradict one another.

    标答:
    Consider fairness and real time. Fairness requires that each process be allocated
    its resources in a fair way, with no process getting more than its fair
    share. On the other hand, real time requires that resources be allocated based
    on the times when different processes must complete their execution. A realtime
    process may get a disproportionate share of the resources.
    

    15. Consider a computer system that has cache memory, main memory (RAM) and disk,
    and an operating system that uses virtual memory. It takes 1 nsec to access a word
    from the cache, 10 nsec to access a word from the RAM, and 10 ms to access a word
    from the disk. If the cache hit rate is 95% and main memory hit rate (after a cache
    miss) is 99%, what is the average time to access a word?

    t = (0.95 * 1ns)(命中缓存)
        + (0.05 * 0.99 * 10ns)(没命中缓存但命中内存)
    	+ (0.05 * 0.01 * 10ms)(都没命中) = 5001.445 ns
    

    23. A file whose file descriptor is fd contains the following sequence of bytes:
    3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5. The following system calls are made:
    lseek(fd, 3, SEEK SET);
    read(fd, &buffer, 4);
    where the lseek call makes a seek to byte 3 of the file. What does buffer contain after
    the read has completed?

    a[]={3,1,4,1,5,9,2,6,......}
    a[0]=3
    lseek(,3,)之后:a[0+3]=a[3]=4
    read(,,4)就是取a[3]~a[3+4-1]
    即1 5 9 2
    

    33. Here are some questions for practicing unit conversions:
    (a) How long is a nanoyear in seconds?
    (b) Micrometers are often called microns. How long is a megamicron?
    (c) How many bytes are there in a 1-PB memory?
    (d) The mass of the earth is 6000 yottagrams. What is that in kilograms?

    翻书,嗯背,我也不会
    mmnpfazy
    KMGTPEZY
    image


    第二章 进程与线程

    A computer has 4 GB of RAM of which the operating system occupies 512 MB.
    The processes are all 256 MB (for simplicity) and have the same characteristics.
    If the goal is 99% CPU utilization, what is the maximum I/O wait that can be tolerated?

    (中文书p54)利用率=1-pow(p,n)
    因为cpu占用率99%,0.99=1-pow(p,n),pow(p,n)=0.01
    题目需要算p(I/O wait)
    每个进程256MB,当前还能装得下(4096MB-512MB)/256MB=14个进程(这个算的是n)
    pow(p,14)=0.01
    p=0.72
    
    

    18. What is the biggest advantage of implementing threads in user space? What is the
    biggest disadvantage?

    最大的优点是高性能,无需陷入内核切换线程;
    最大的缺点是一旦某个线程被阻塞,会导致整个进程阻塞
    

    45. Five batch jobs. A through E, arrive at a computer center at almost the same time.
    They hav e estimated running times of 10, 6, 2, 4, and 8 minutes. Their (externally determined)
    priorities are 3, 5, 2, 1, and 4, respectively, with 5 being the highest priority.
    For each of the following scheduling algorithms, determine the mean process
    turnaround time. Ignore process switching overhead.
    (a) Round robin.
    (b) Priority scheduling.
    (c) First-come, first-served (run in order 10, 6, 2, 4, 8).
    (d) Shortest job first.
    For (a), assume that the system is multiprogrammed, and that each job gets its fair
    share of the CPU. For (b) through (d), assume that only one job at a time runs, until it
    finishes. All jobs are completely CPU bound.

    (a)轮转调度(每次从剩余的进程中选出最小的,所有减去最小的,直到全部完成)
    每个进程平均完成时间(10 + (10+8) + (10+8+6) + (10+8+6+4) + (10+8+6+4+2))/5 = 22mins
    顺序:(
    10 6 2 4 8 (cost 10mins)
    8 4 0 2 6 (cost 8mins)
    6 2 0 0 4 (cost 6mins)
    4 0 0 0 2 (cost 4mins)
    2 0 0 0 0 (cost 2mins)
    0 0 0 0 0
    )
    
    (b)优先级调度(按题目要求先执行优先级大的再执行小的)
    顺序:6 8 10 2 4
    t = (6 + 14 + 24 + 26 + 30) / 5 = 20mins
    
    (c)先来先服务(按顺序即可)
    t = (10 + 16 + 18 + 22 + 30) / 5 = 19.2mins
    
    (d)最短作业优先(从小到大执行)
    顺序:2 4 6 8 10
    t = (2 + 6 + 12 + 20 + 30) / 5 = 14mins
    

    60. Suppose that a university wants to show off how politically correct it is by applying the
    U.S. Supreme Court’s ‘‘Separate but equal is inherently unequal’’ doctrine to gender as
    well as race, ending its long-standing practice of gender-segregated bathrooms on campus.
    However, as a concession to tradition, it decrees that when a woman is in a bathroom,
    other women may enter, but no men, and vice versa. A sign with a sliding
    marker on the door of each bathroom indicates which of three possible states it is currently
    in:
    • Empty
    • Women present
    • Men present
    In some programming language you like, write the following procedures:
    woman wants to enter, man wants to enter, woman leaves, man leaves. You
    may use whatever counters and synchronization techniques you like.

    开放题,不知道这样写对不对
    
    semaphore mutex = 1;
    int flag = 0;
    int man = 0, woman = 0;
    
    void man_wants_to_enter()
    {
    	while(flag != 1)
    		P(mutex), flag = 1;
    	man++;
    }
    
    void woman_wants_to_enter()
    {
    	while(flag != 2)
    		P(mutex), flag = 2;
    	woman++;
    }
    
    void man_leaves()
    {
    	if (flag == 1)
    	{
    		man--;
    		if (!man)
    			flag = 0, V(mutex);
    	}
    }
    
    void woman_leaves()
    {
    	if (flag == 2)
    	{
    		woman--;
    		if (!woman)
    			flag = 0, V(mutex);
    	}
    }
    
    

    第三章 内存管理

    4.Consider a swapping system in which memory consists of the following hole sizes in
    memory order: 10 MB, 4 MB, 20 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB.
    Which hole is taken for successive segment requests of
    (a) 12 MB
    (b) 10 MB
    (c) 9 MB
    for first fit? Now repeat the question for best fit, worst fit, and next fit

    First fit takes 20 MB, 10 MB, 18 MB. Best fit takes 12 MB, 10 MB, and 9
    MB. Worst fit takes 20 MB, 18 MB, and 15 MB. Next fit takes 20 MB, 18
    MB, and 9 MB.
    
    首次适配:从前往后找到第一个可以放入的块
    先把12MB放入20MB,现在变成10 MB, 4 MB, 8 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB
    再10MB放入10MB,变成0 MB, 4 MB, 8 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB
    最后把9MB放入18MB,变成0 MB, 4 MB, 8 MB, 9 MB, 7 MB, 9 MB, 12 MB, and 15 MB
    
    最佳适配:找到可以放入的最小块
    先把12MB放入12MB,现在变成10 MB, 4 MB, 20 MB, 18 MB, 7 MB, 9 MB, 0 MB, and 15 MB.
    再10MB放入10MB,变成0 MB, 4 MB, 20 MB, 18 MB, 7 MB, 9 MB, 0 MB, and 15 MB.
    最后把9MB放入9MB,变成0 MB, 4 MB, 20 MB, 18 MB, 7 MB, 0 MB, 0 MB, and 15 MB.
    
    最差适配:找到可以放入的最大块
    先把12MB放入20MB,现在变成10 MB, 4 MB, 8 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB.
    再10MB放入18MB,变成10 MB, 4 MB, 8 MB, 8 MB, 7 MB, 9 MB, 12 MB, and 15 MB.
    最后把9MB放入15MB,变成10 MB, 4 MB, 8 MB, 8 MB, 7 MB, 9 MB, 12 MB, and 6 MB.
    
    下次适配:从上次适配结束的点向前找到第一个适配的块
    先把12MB放入20MB,现在变成(10 MB, 4 MB, )8 MB, 18 MB, 7 MB, 9 MB, 12 MB, and 15 MB
    再10MB放入18MB,变成(10 MB, 4 MB,) (8 MB, )8 MB, 7 MB, 9 MB, 12 MB, and 15 MB
    最后把9MB放入9MB,变成(10 MB, 4 MB,) (8 MB, )(8 MB, 7 MB,) 0 MB, 12 MB, and 15 MB
    
    )
    
    

    19. A computer with a 32-bit address uses a two-level page table. Virtual addresses are
    split into a 9-bit top-level page table field, an 11-bit second-level page table field, and
    an offset. How large are the pages and how many are there in the address space?

    偏移量=32-9-11=12位
    所以页面大小为pow(2,12)B=4KB
    地址空间中的页面个数:pow(2,9+11)=1M个
    (一级页表总共指向pow(2,11)个页面,二级页表指向pow(2,9)个一级页表)
    

    28. If FIFO page replacement is used with four page frames and eight pages, how many
    page faults will occur with the reference string 0172327103 if the four frames are initially
    empty? Now repeat this problem for LRU.

    image

    32. In the WSClock algorithm of Fig. 3-20(c), the hand points to a page with R = 0. If
    τ = 400, will this page be removed? What about if τ = 1000?

    The age of the page is 2204 − 1213 = 991. 
    If τ = 400, it is definitely out of the working set and was not recently referenced so it 
    will be evicted.
    The τ = 1000 situation is different(991 <= 1000 it is in the working set). Now the page falls 
    within the working set (barely), so it is not removed.
    

    36. A computer has four page frames. The time of loading, time of last access, and the R
    and M bits for each page are as shown below (the times are in clock ticks):
    image
    (a) Which page will NRU replace?
    (b) Which page will FIFO replace?
    (c) Which page will LRU replace?
    (d) Which page will second chance replace?

    (中文书p118)
    NRU removes page 2.(优先删R=0,m=0(00)的,然后是01,再是10,最后是11)
    FIFO removes page 3.(删载入时间最早的)
    LRU removes page 1.(删最近访问时间最早的)
    Second chance removes page 2.(
    按照载入时间依次入队
    然后从队首开始
    如果R为1,则置为0,放到队尾
    如R为0,删掉它,流程结束
    )
    

    47. We consider a program which has the two segments shown below consisting of instructions
    in segment 0, and read/write data in segment 1. Segment 0 has read/execute protection,
    and segment 1 has just read/write protection. The memory system is a demand-paged virtual
    memory system with virtual addresses that have a 4-bit page number, and
    a 10-bit offset. The page tables and protection are as follows (all numbers in the table
    are in decimal):
    image
    For each of the following cases, either give the real (actual) memory address which results
    from dynamic address translation or identify the type of fault which occurs (either
    page or protection fault).
    (a) Fetch from segment 1, page 1, offset 3
    (b) Store into segment 0, page 0, offset 16
    (c) Fetch from segment 1, page 4, offset 28
    (d) Jump to location in segment 1, page 3, offset 32

    (a)不会出错,地址为11100000000011(or 1110 0011 or 0xD3)
    (b)保护错误: Write to read/execute segment
    (c)缺页错误
    (d)保护错误: Jump to read/write segment
    

    第四章 文件系统

    21. Name one advantage of hard links over symbolic links and one advantage of symbolic
    links over hard links.

    硬链接不需要额外的磁盘空间,只需要i-node上的一个counter去持续记录有多少目录项指向它。
    符号链接需要空间去存储它指向文件的名称,并且符号链接可以指向其他机器或者网络上的文件。
    

    23. Consider a 4-TB disk that uses 4-KB blocks and the free-list method. How many block
    addresses can be stored in one block?

    4TB/4KB = pow(2,30)块,32是比它大又最接近的2进制位(lower_bound),因此每个块地址可以是32位(4Byte).
    每个块可以存储4KB/4B = 1024个块地址
    

    36. Consider the idea behind Fig. 4-21, but now for a disk with a mean seek time of 6
    msec, a rotational rate of 15,000 rpm, and 1,048,576 bytes per track. What are the data
    rates for block sizes of 1 KB, 2 KB, and 4 KB, respectively?

    中文书(p168):假设磁盘每道1MB,其旋转时间为8.33ms,平均寻道时间为5ms。
    读取一个k个字节的块所需的时间是寻道时间、旋转延迟和传送时间之和:5 + 4.165 + (k/1MB)*8.33
    
    旋转时间(转一圈要花的时间): 60s/15000rpm = 4ms/r
    寻道时间 :6ms
    每道大小 :1048576B
    套公式得: 6 + 4/2 + (k/1048576) * 4
    
    For blocks of 1 KB, 2 KB, and 4 KB(把这3个当成k代入), the access times are about 8.0039 msec, 
    8.0078msec, and 8.0156 msec, respectively (hardly any different).
    
    传输1KB需要8.0039ms,那么1s传输1000/8.0039*1 KB/s
    同理。。。
    
    

    40. A UNIX file system has 4-KB blocks and 4-byte disk addresses. What is the maximum
    file size if i-nodes contain 10 direct entries, and one single, double, and triple indirect
    entry each?

    The i-node holds 10 pointers. The single indirect block holds 1024 pointers.
    The double indirect block is good for 10242 pointers. The triple indirect block
    is good for 10243 pointers. Adding these up, we get a maximum file size of
    1,074,791,434 blocks, which is about 16.06 GB.
    
    4KB/4B = 1024块地址/每块
    
    直接表项:10
    一次间接块:1024
    二次间接块:1024*1024
    三次间接块:1024*1024*1024
    
    相加得:1074791434块,每块4KB(solution给的是16.06GB,不知道是不是我理解的有问题)
    
    

    第五章 I/O

    13. Explain how an OS can facilitate installation of a new device without any need for
    recompiling the OS.

    对每种设备类型,操作系统定义一组驱动程序必须支持的函数。驱动程序通常包含一张table,具有这些函数指向驱
    动程序自身的指针。当新的驱动程序装载时,操作系统记录这张表格的地址,在表中新建一个条目,并将指向驱动程
    序的函数指针填入。
    

    28. Consider a magnetic disk consisting of 16 heads and 400 cylinders. This disk has four
    100-cylinder zones with the cylinders in different zones containing 160, 200, 240. and
    280 sectors, respectively. Assume that each sector contains 512 bytes, average seek
    time between adjacent cylinders is 1 msec, and the disk rotates at 7200 RPM. Calculate
    the (a) disk capacity, (b) optimal track skew, and (c) maximum data transfer rate.

    容量(disk capacity): 磁头数 * 柱面数 * 扇区数

    Capacity of zone 1: 16 × 100 × 160 × 512 = 131072000 bytes
    Capacity of zone 2: 16 × 100 × 200 × 512 = 163840000 bytes
    Capacity of zone 3: 16 × 100 × 240 × 512 = 196608000 bytes
    Capacity of zone 4: 16 × 100 × 280 × 512 = 229376000 bytes
    Sum = 131072000 + 163840000 + 196608000 + 229376000 = 720896000
    

    最优磁道斜进(中文书p211): 寻道时间 / 通过每个扇区需要的时间

    A rotation rate of 7200 means there are 120 rotations/sec.
    In the 1 msec track-to-track seek time, 0.120 of the sectors are covered.//1ms转0.12圈
    
    
    //4个柱面通过每个扇区需要的时间不同,分别计算
    In zone 1, the disk head will pass over 0.120 × 160 sectors in 1 msec, so, optimal track
    skew for zone 1 is 19.2 sectors.(1ms转0.12*160 = 19.2个扇区)
    
    In zone 2, the disk head will pass over
    0.120 × 200 sectors in 1 msec, so, optimal track skew for zone 2 is 24 sectors.
    
    In zone 3, the disk head will pass over 0.120 × 240 sectors in 1 msec,
    so, optimal track skew for zone 3 is 28.8 sectors.
    
    In zone 4, the disk head will pass over 0.120 × 280 sectors in 1 msec, so, optimal track skew for zone 3 is 33.6 sectors.
    
    
    最大数据传输率:
    	数据传输率=转速 * 扇区数 * 每个扇区的大小
    	4个柱面转速相同,每个扇区的大小相同,那么扇区数选最大的:120*280*512=17203200 Byte/s
    

    31. Disk requests come in to the disk driver for cylinders 10, 22, 20, 2, 40, 6, and 38, in
    that order. A seek takes 6 msec per cylinder. How much seek time is needed for
    (a) First-come, first served.
    (b) Closest cylinder next.
    (c) Elevator algorithm (initially moving upward).
    (d) 改进的电梯算法
    In all cases, the arm is initially at cylinder 20.

    
    (a)FCFS:按照给的顺序把距离求出来相加然后乘寻道时间即可
    	sum = (20-10)+(22-10)+(22-20)+(20-2)+(40-2)+(40-6)+(38-6) = 146ms
    	6 * sum = 876 ms
    (b)SSF:由于从20开始,每次找离当前位置最近的,求和乘寻道时间
    	6 * (2+12+4+4+36+2)=360ms
    	顺序:20 22 10 6 2 38 40
    (c)elevator(中文书P214):从开始位置先向上遍历完所有上面的请求再往下跑
    	6*(2+16+2+30+4+4)=348ms
    	顺序:20 22 38 40 10 6 2
    (d)改进:从开始位置先向上遍历完所有上面的请求  再去最低的没有完成的请求处往上遍历
    	6*(2+16+2+38+4+4)=396ms
    	顺序:20 22 38 40 2 6 10
    

    50. A thin-client terminal is used to display a Web page containing an animated cartoon of
    size 400 pixels × 160 pixels running at 10 frames/sec. What fraction of a 100-Mbps
    Fast Ethernet is consumed by displaying the cartoon?

    consumed = fps * 长 * 宽 * 像素大小 / 带宽 * 100%
    	 = 10*400*160* 3Byte(24bit) / (100Mb/s) = 15.36%
    
  • 相关阅读:
    数据库概念相关
    JavaWeb基础知识总结
    MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
    MyBatis学习总结(一)——MyBatis快速入门
    [源码解析]HashMap和HashTable的区别(源码分析解读)
    MyBatis学习总结(三)——优化MyBatis配置文件中的配置
    MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
    MyBatis学习总结(五)——实现关联表查询
    MyBatis学习总结(六)——调用存储过程
    MyBatis学习总结(七)——Mybatis缓存
  • 原文地址:https://www.cnblogs.com/ruanbaiQAQ/p/14819840.html
Copyright © 2011-2022 走看看