《西安电子科技大学操作系统期末试题及答案解析(共17页).docx》由会员分享,可在线阅读,更多相关《西安电子科技大学操作系统期末试题及答案解析(共17页).docx(17页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上 西 安 电 子 科 技 大 学考试时间 120 分钟 试题题号一二三四五六七八九十总分分数1.考试形式:闭卷 2.考试日期: 年 月 日 3.本试卷共 四 大题,满分100分班级 学号 姓名 任课老师 Part 1: Select one answer (A through D) for each question ( Total 20, each 2 )1. A computer system consists of , system programs and application programs.A. Control bus B. data busC. Ad
2、dress bus D. hardware2. Thread(线程)can be implemented in .A. Kernel SpaceB. User SpaceC. Kernel Space or User SpaceD. None of the above3. In OS, short term schedule(调度)means .A. Job schedulingB. Process schedulingC. Thread schedulingD. CPU scheduling4. Which one of the following item is not shared by
3、 all threads in a process? .A. Address spaceB. RegisterC. Open files D. Accounting information5. In the paged memory management system, the address is composed of page number and the offset within the page. In the address structure shown in the following figure, . 31 10 9 0page numberoffsetA. page s
4、ize is 512, 2M pages at mostB. page size is 1k, 4M pages at mostC. page size is 2k, 8M pages at mostD. page size is 4k, 16M pages at most6. Virtual memory is based on The Principle of Locality. Which of the following statements about The Principle of Locality is correct? A. Program executes codes in
5、 orderB. Program assesses(访问)memory in a non-uniform mannerC. Program accesses a lot of variables continuouslyD. Program accesses a relatively small portion of the address space at any instant of time7. In UNIX i-node scheme, a directory entry contains only two fields: the file name (14 bytes) and t
6、he number of the i-node for that file (2 bytes). These parameters(参数)limit the number of files per file system to .A. 64k B. 32kC. 16kD. 4k8. The time required to read or write a disk block is determined(决定)by three factors. Which one dominates(主导,占优势)the other two times? .A. Seek timeB. Rotational
7、delay timeC. Data transfer timeD. None of above9. The chmod command(命令)is used to change the permission(许可)of file in Linux. To use it, you specify the desired permission setting and the file or files that you wish to modify. The permission settings are usually a series of bits. Which of the followi
8、ng bits present that the files owner may read, write, and execute the file, while all others may only read the file? .A. 755 B. 744 C. 644D. 61110. The method listed below doesnt need CPU to participate in the transfer of data block.A. Interrupt-Driven I/OB. DMAC. Programmed I/OD. None of abovePart2
9、: Fill Blanks (Total 20, each 2)1. Operating System is an extended machine and .2. Parallel Systems include Symmetric(对称)multiprocessing and .3. A semaphore(信号量)S is an integer variable that is accessed only through two standard atomic operations: and .4. Address binding of instructions and data to
10、memory addresses can happen at three different stages, Compile time, Load time and .5. Four Conditions for Deadlock: , Hold and wait, No preemption and .6. Sector 0 of the disk is called the .7. In Linux, the file metadata(元数据)is stored in .8. The security goals include data confidentiality(机密性),dat
11、a integrity and .Part3: Essay Questions (Total 20, each 4)1. What is system call? Use an example to illustrate(举例说明)the steps of system call.2. Please describe the diagram(图)of Process State.3. What is Monitor? Can you use Monitor to implement a data structure?4. What is TLB? What role does it play
12、in memory management?5. The difference of programming I/O and interrupt-driven I/O.Part4: Integrate Questions (Total 40, each 10)1. The code below is an example program of producer-consumer. The product produce numbers from 1 to MAX and the consumer will read it. Please fill blanks in the code#inclu
13、de #include #define MAX /* how many numbers to produce */pthread_mutex_t the_mutex;pthread_cond_t condc, condp;int buffer = 0; /* buffer used between producer and consumer*/void *producer(void *ptr) /*produce data*/int i;for (i=1; i=MaX; i+) pthread_mutex_lock(&the_mutex);while ( )pthread_cond_wait
14、(&condp, &the_mutex);buffer = i; pthread_exit (0);void *consumer (void *ptr) /*consume data*/int i, res;for (i = 1; i=MAX; i+) pthread_mutex_lock (&the_mutex);while ( )pthread_cond_wait ( , &the_mutex);res = buffer;buffer = 0;pthread_cond_signal(&condp); printf(“buffer=%dn” , res); pthread_exit (0);
15、int main (int argc, char *argv)pthread_t pro,con;pthread_mutex_init (&the_mutex, 0);pthread_cond_init (&condc, 0);pthread_cond_init (&condp, 0);pthread_create (&con, 0, consumer, 0);pthread_create (&pro, 0, producer, 0);pthread_join (pro, 0);pthread_join (con, 0);pthread_cond_destroy (&condc);pthrea
16、d_cond_destroy (&condp);pthread_mutex_destroy (&the_mutex);2. Consider the following snapshot of a system : ResourcesProcessesAllocationA B C DMax NeedA B C DAvailableA B C DP0P1P2P3P40 0 1 21 0 0 01 3 5 40 6 3 20 0 1 40 0 1 21 7 5 02 3 5 60 6 5 20 6 5 6 1 5 2 0Answer the following questions using t
17、he bankers algorithm:(1) What is the content of the matrix Need? (4 points)(2) Is the system in safe state? Why? (3 points)(3) If a request from process P1 arrives for (0,4,2,0), can the request be granted(允许)immediately? (3 points)3. Disk requests come in to the disk driver for cylinders 10,22,20,2
18、,40,6, and 38, in that order. In all cases, the arm is initially at cylinder 20. A seek takes 6 msec per cylinder moved. How much seek times is needed for(1) First Come First Served (FCFS).(3 points)(2) Shorted Seek Time First (SSTF).(3 points)(3) Elevator algorithm (SCAN, initially moving upward)(4
19、 points)4. Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory consists of 4 page frames. Now consider a process which requires 8 pages of storage. At some point during its execution, the page table is as shown below:Virtual pageValidPhysical page0No1No2Yes13No4Y
20、es35No6Yes07Yes2Answer the following questions:(1) List the virtual address ranges for each virtual page.(3 points)(2) List the virtual address ranges that will result in a page fault. (3 points)(3) Give the main memory (physical) addresses for each of the following virtual addresses (all numbers de
21、cimal): (i) 8500, (ii) 1400, (iii) 5000, (iv) 2100.(4 points)AnswersPart 1: Select one answer (A through D) for each question1.D计算机系统由硬件和软件(系统程序+应用程序)组成。2.C线程实现的两种方式用户空间和内核中 在用户空间中实现线程 内核对线程包一无所知,从内核角度考虑,就是按正常的方式 管理,即单线程进程(存在运行时系统) 在内核中实现线程 在某个线程希望创建一个新线程或撤销一个已有线程时,它进行一个系统调用,这个系统调用通过对线程表的更新完成线程创建和撤销
22、工作。 混合实现 在此模型中,每个内核级线程有一个可以轮流使用的用户级线程集合。3.D三级调度: long-term schedule(长期调度,又称作业调度):哪个程序被系统选中并创建进程运行它 medium-term schedule(中期调度,又称内存调度):决定是否将进程调入内存 short-term schedule(短期调度,又称CPU调度):哪个进程获得处理器资源(通常所说的调度)4.B一个进程中所有线程共享的内容(进程的属性): 每个线程独有的内容: 5.B页面数(page number) = = = 4M由页内偏移(offset)得,页面大小(page size) = = =
23、 1K6.D 答案:程序在一段时间内访问相对小的一段地址空间虚拟内存基于程序的局部性原理而设计的。程序的局部性原理是指程序在执行时呈现出局部规律,即在一段时间内,整个程序的执行仅限于程序中的某一部分。相应地,执行所访问的存储空间也局限于某个内存区域。(根据程序的局部性理论,Denning 提出了工作集理论)7.AUNIX的一个目录项包含了两个域,文件名(14个字节)和节点的编号(2个字节),这些参数决定了每个文件系统的文件数目为64K( )8.ATime required to read or write a disk block determined by 3 factors: Seek t
24、ime (the time to move the arm to the proper cylinder)(寻道时间) Rotational delay (the time for the proper sector to rotate under the head)(旋转延迟) Actual data transfer time (实际数据传输时间)For most disks, the seek time dominates the other two times.9.Bchmod 命令,改写文件的读写许可设置语法为:chmod abc file其中a,b,c各为一个数字,分别表示User
25、, Group, Other的权限r = 4, w = 2, x = 1所以,a = 4+2+1 = 7b = 4c = 410. B I/O可以以三种不同方式实现: 程序控制I/O (Programmed I/O) 让CPU做全部的工作。CPU通过程序主动读取状态寄存器以了解接口情况,并完成相应的数据操作。 中断驱动I/O (interrupt-driven I/O) 当程序常规运行时,若外部有优先级更高的事件出现,则通过中断请求通知CPU,CPU再读取状态寄存器确定事件的种类,执行不同的分支处理。 DMA (Direct Memory Access) 直接内存存取即数据传送的具体过程直接由
26、硬件(DMA控制器)在内存和I/O之间完成,CPU只在开始时将控制权暂时交予DMA,直到数据传输结束。Part2: Fill Blanks1. a resource manager2. asymmetric multiprocessing (非对称多处理)3. PV4. execution time5. Mutual exclusion Circular wait6. MBR(Master Boot Record) 主引导记录7. i-node8. system availabilityPart3: Essay Questions1. 操作系统的主要功能是为应用程序的运行创建良好的环境,为了达
27、到这个目的,内核提供一系列具备预定功能的多内核函数,通过一组称为系统调用(system call)的接口呈现给用户。系统调用把应用程序的请求传给内核,调用相应的的内核函数完成所需的处理,将处理结果返回给应用程序,如果没有系统调用和内核函数,用户将不能编写大型应用程序。2. 1)Running运行态 2)Ready 就绪态.,暂无CPU分配得它。3)Blocked 阻塞态,等待输入 3. 管程是一个由过程、变量和数据结构等组成的一个集合,它们组成一个特殊的模块或软件包。进程可在任何需要的时候调用管程中的过程,但它们不能在管程之外声明的过程中直接访问管程内的数据结构。任一时刻管程中只能有一个活跃进
28、程,这一特性使管程能有效地完成互斥。4. TLB即Translation Lookaside Buffer(转换检测缓冲区),是一个小型的硬件设备将虚拟地址直接映射到物理地址,不必再访问列表。它通常存在在MMU中,包含少量的表项,每个表项记录了一个页面的相关信息,包括虚拟页号、页面的修改位、保护码(读/写/执行权限)和该页所对应的物理页框。它是一个内存管理单元用于改进虚拟地址到物理地址转换速度的缓存。5. 程序控制I/O (Programmed I 让CPU做全部的工作。CPU通过程序主动读取状态寄存器以了解接口情况,并 完成相应的数据操作。 中断驱动I/O (interrupt-driven
29、 I/O) 在等待设备就绪的时候允许CPU做其他的事情。当程序常规运行时,若外部有优先级更高的事件出现,则通过中断请求通知CPU,CPU再读取状态寄存器确定事件的种类,执行不同的分支处理。Part4: Integrate Questions1. buffer != 0 pthread_cond_signal(&condc); pthread_mutex_unlock(&the_mutex); buffer = 0 &condc pthread_mutex_unlock(&the_mutex);2. (1) (= MAX Need -Allocation) (2) 此时系统状态是不安全的。因为:
30、不存在使所有进程都顺序执行的序列。A = (1 5 2 0)P0markedA = (1 5 2 0)P3markedA = (1 5 4 0)进程执行顺序:P0,P3,但是剩余资源不能满足其他进程的需求 (3) 允许。因为存在使进程都顺序执行的序列:P0,P3,P1,P2,P4A = (1 5 2 0)P0markedA = (1 5 2 0)P3markedA = (1 5 4 0)P1markedA = (1 8 7 0)P2markedA = (2 8 7 2)P4markedA = (2 14 11 4)3. (1) FCFS 柱面访问序列:(20),10,22,20,2,40,6,
31、38 磁盘臂访问序列:(20),10,22,20,2,40,6,38(10+12+2+18+38+34+32)X6 = 876msec(2) SSTF 柱面访问序列:(20),10,22,20,2,40,6,38 磁盘臂访问序列:20,22,10,6,2,38,40(2+12+4+4+36+2)X6 = 360msec(3) elevator 柱面访问序列:(20),10,22,20,2,40,6,38 磁盘臂访问序列:20,22, 38,40,10,6,2(2+16+2+30+4+4)X6 = 348msec4. (1) 714k-16k612k-14k510k-12k48k-10k36k-8k24k-6k12k-4k00k-2k(2) 0k-2k, 2k-4k, 6k-8k, 10k-12k(3)8500140050002100页面大小页号偏移量页号偏移量页号偏移量页号偏移量2KB4308014002904152 8500:页号P = INT 8500/2048 = 4偏移量 offset = 8500 MOD 2048 = 308 其他类似专心-专注-专业