上海交通大学试卷(A卷) (2012至2013学年第2_学期) 班级号 学号 姓名 课程名称Operating System 成绩 Part I:Filling the blanks(20%) 1.A computer system can be divided roughly into four components: and 2.Java applications are typically compiled to (class file)that can run on any JVM regardless of computer architecture. 3.Analyze the following program: #include #include #include int value 12; int mainO { pid t pid; pid forkO; if (pid ==0){ value +=20; else if (pid >0){ wait(NULL); printf(“PARENT:value=%d”,value);LINE A*/ exit(O); The output of value at LINE A is 4.A socket is defined as an endpoint for communication.A socket is identified by an concatenated with a A卷总8_页第_1页
A 卷 总 8 页 第 1 页 Part I: Filling the blanks ( 20%) 1. A computer system can be divided roughly into four components: _______________, ______________, _______________ and _______________. 2. Java applications are typically compiled to _______________ (class file) that can run on any JVM regardless of computer architecture. 3. Analyze the following program: #include #include #include int value = 12; int main() { pid_t pid; pid = fork(); if (pid ==0) { value +=20; } else if (pid > 0) { wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A*/ exit(0); } } The output of value at LINE A is _______________. 4. A socket is defined as an endpoint for communication. A socket is identified by an _____________________ concatenated with a _____________________. 上 海 交 通 大 学 试 卷( A 卷) ( 2012 至 2013 学年 第_2__学期 ) 班级号_______________________ 学号______________ 姓名 课程名称 Operating System 成绩
4 6 8 我承诺,我将严 题号 格遵守考试纪律。 得分 承诺人: 批阅人(流水阅 卷教师签名处) 5.Many criteria have been suggested for comparing CPU scheduling algorithms.The criteria include: and 6.A situation like this,where several processes access and manipulate the same data and the outcome of execution depends on the 公 which the access takes place is called 7.A process is if it is spending more time paging than executing. 8.Normally devices can be divided into and Part II.Problems (80%) 1.Describe the differences between the process and the thread in the thread model. A卷总8_页第2页
A 卷 总 8 页 第 2 页 5. Many criteria have been suggested for comparing CPU scheduling algorithms. The criteria include: _________________, _________________, _________________, _________________, and _________________. 6. A situation like this, where several processes access and manipulate the same data _____________ and the outcome of execution depends on the ___________________ in which the access takes place is called ________________________. 7. A process is ______________ if it is spending more time paging than executing. 8. Normally devices can be divided into _____________________, ___________________ and ____________________________. Part II. Problems ( 80%) 1. Describe the differences between the process and the thread in the thread model. 题号 I II 1 2 3 4 5 6 7 8 得分 批阅人(流水阅 卷教师签名处) 我承诺,我将严 格遵守考试纪律。 承诺人:
2.Consider three processes,pl,p2 and p3,executing asynchronously the following sequences of code: p1 p2 p3 x.acquire() y.acquire() z.acquire() -z.acquire() y.acquire() >x.acquire() x.release() z.release() z.release() x.release() The arrow in each line indicates which instruction the corresponding process is currently executing.All semaphores were initially set to 1. (a)Draw a resource graph describing the above situation where each semaphore is interpreted as a resource,and acquire()and release()operations represent the requests and releases of the resources. (b)Is there a deadlock state? (c)If you could increase the number of units of any of the three resources,which increase(if any) would resolve the deadlock? A卷总8_页第_3_页
A 卷 总 8 页 第 3 页 2. Consider three processes, p1, p2 and p3, executing asynchronously the following sequences of code: p1 p2 p3 . . . x.acquire() . . . z.acquire() . . . x.release() . . . z.release() . . . y.acquire() . . . y.acquire() . . . . . . z.acquire() . . . x.acquire() . . . z.release() . . . x.release() The arrow in each line indicates which instruction the corresponding process is currently executing. All semaphores were initially set to 1. (a) Draw a resource graph describing the above situation where each semaphore is interpreted as a resource, and acquire() and release() operations represent the requests and releases of the resources. (b) Is there a deadlock state? (c) If you could increase the number of units of any of the three resources, which increase(if any) would resolve the deadlock?
3.Discuss how the following pairs of scheduling criteria conflict in certain settings. a.CPU utilization and response time. b.Average turnaround time and maximum waiting time. c.I/O device utilization and CPU utilization. 4.Name two methods that I/O devices notify the cpu.Discuss the pros and cons of each method. Give some examples using the two methods. A卷总_8_页第_4_页
A 卷 总 8 页 第 4 页 3. Discuss how the following pairs of scheduling criteria conflict in certain settings. a. CPU utilization and response time. b. Average turnaround time and maximum waiting time. c. I/O device utilization and CPU utilization. 4. Name two methods that I/O devices notify the cpu. Discuss the pros and cons of each method. Give some examples using the two methods
5.Consider the following inverted page table in a paging system.Assuming page tables were used instead of the inverted page table,show the contents of the corresponding page tables. Frame no. pid Page no. 0 3 1 1 7 4 2 3 0 3 3 2 4 7 1 5 7 2 6 7 0 7 7 3 6.Discuss how the following pairs of scheduling criteria conflict in certain settings. a.CPU utilization and response time. b.Average turnaround time and maximum waiting time. c.I/O device utilization and CPU utilization. A卷总_8_页第5页
A 卷 总 8 页 第 5 页 5. Consider the following inverted page table in a paging system. Assuming page tables were used instead of the inverted page table, show the contents of the corresponding page tables. Frame no. pid Page no. 0 3 1 1 7 4 2 3 0 3 3 2 4 7 1 5 7 2 6 7 0 7 7 3 6. Discuss how the following pairs of scheduling criteria conflict in certain settings. a. CPU utilization and response time. b. Average turnaround time and maximum waiting time. c. I/O device utilization and CPU utilization
7.Consider the analogy of a tunnel with only a single lane.To avoid a deadlock,cars must be prevented from entering the tunnel at both ends simultaneously.Once a car enters,other cars from the same direction may follow immediately.Ignoring the problem of starvation,write the code using semaphores to solve this problem. (a)Define the semaphores and set their initial values: (b)Implement the functions by filling the blanks. North({ if Enter Tunnel; if( SouthO{ /*Same with the North()*/ 7.The following diagrams show portions of several data structures of a file system.Each entry of the directory contains the symbolic name of a file,together with the index node number of the file. A卷总8_页第_6页
A 卷 总 8 页 第 6 页 7. Consider the analogy of a tunnel with only a single lane. To avoid a deadlock, cars must be prevented from entering the tunnel at both ends simultaneously. Once a car enters, other cars from the same direction may follow immediately. Ignoring the problem of starvation, write the code using semaphores to solve this problem. (a)Define the semaphores and set their initial values: (b) Implement the functions by filling the blanks. North() { ___________________; ___________________; if (_____________________) _______________________; ____________________; Enter Tunnel; _____________________; _____________________; if (_____________________________) ___________________; _______________________________; } South(){ /*Same with the North() */ } 7. The following diagrams show portions of several data structures of a file system. Each entry of the directory contains the symbolic name of a file, together with the index node number of the file
Block 132 I-node 26 Block 406 I-node 6 is /usr is for is /usr/ast Root directory is for /usr directory /usr/ast directory Open File Table 26 Mode Mode 1 6 i-node Curr. size size times times No. pos. 4 bin 19 dick 64 grants g年 7 dev 132 30 enk 406 92 books 7 free 14b 51 jim 60 mbox 9 etc 26 ast 81 minix 8 92 55 6 usr 45 bal 17 SrC 9 free 8 tmp Illustrate each of the following operations and show all changes to the data structure in the diagrams above. (a)open the file mbox:fd=open("/usr/ast/mbox") (b)seek to position 60 of the open mbox file:seek(fd,60) (c)close the file mbox:close(fd) 8.Following is a C program in Unix system. (a)Please give the notes for each system call. include include main ( A卷总8页第7页
A 卷 总 8 页 第 7 页 free 9 8 7 92 55 free Open File Table Curr. pos. i-node No. ... ... ... ... Illustrate each of the following operations and show all changes to the data structure in the diagrams above. (a) open the file mbox: fd=open(“/usr/ast/mbox”) (b) seek to position 60 of the open mbox file: seek(fd,60) (c) close the file mbox: close(fd) 8. Following is a C program in Unix system. (a)Please give the notes for each system call. # include # include main ( ) {
int status; pid t pid; void func () signal(SIGUSR1,func);/ * if (pid=fork()){ kil(pid,SIGUSR1)/快 wait(&status):/六 */ printf("status=%d:Parent finish:\n",status); else{ sleep(10);/ exit (0);/* 制 void func { printf("It is signal processing function.In"); } (b)illustrate the function of this program. A卷总8_页第8页
A 卷 总 8 页 第 8 页 int status; pid_t pid; void func ( ); signal (SIGUSR1,func);/*________________________________________________________________ */ if (pid=fork () ) { /*________________________________________________________________*/ kill (pid, SIGUSR1); /* _______________________________________________________ */ wait (& status); /*___________________________________________________________*/ printf ("status=%d: Parent finish:\n",status); } else { sleep (10); /*___________________________________________________________________*/ exit (0);/*___________________________________________________________________*/ } void func () { printf ("It is signal processing function.\n"); } (b) illustrate the function of this program