CS537 Section 2 Midterm Exam Name: ID: I. Write a brief (one or two sentences) definition of each of the following terms. (3 points each) *Note: some of the answers are unnecessarily long in order to help people understand that there are multiple valid answers. * (1) kernel Also called operating system, the kernel is the lowest level of software that directly interacts with hardware, controls accesses to resources and manages their allocation, provides an abstraction to user-level software, runs in priviledged mode. (2) critical section A section of code that only one process or thread can execute at one time. Usually contains accesses to shared variables. If more than one process or thread execute it at the same time, error will occur. (3) the ``blocked'' or ``waiting'' state of a process The state of a process when it is waiting for some I/O operation to finish or waiting to obtain a synchronization resource (for example, locks or semaphores). (4) page fault An interrupt that occurs when a process is trying to access a page (a virtual page), and the page currently does not reside in main memory. (5) virtual memory address The address used by a process to reference a memory location in its address space. The address does not directly correspond to any physical memory location. Rather, it has to be translated through the process' page table in order to generate a physical memory address to access the main memory. (6) process ID An ID number that is assigned by the kernel to uniquely distinguish the process and keep track of the process' contexts. (7) time-sharing systems Computer systems which allow more than one user and more than one process to run on the hardware at the same time, and dynamically switch the CPU among the process to create an illusion that each process has its own CPU. (8) clock interrupt a hardware timer interrupt that occurs at regular intervals (for example, every 10ms), and is used by OS to implement time-sharing of the CPU. (9) physical page number The number that is used to identify a physical page. When put together with the page offset, it produces a physical address that can be used to directly access memory. (10) TLB Translation Lookaside Buffer, a piece of hardware that acts as a cache for the valid virtual to physical translations in all the page tables, used to speed up the virtual-to-physical address translations in modern computers (which support virtual memory). II. For each statement below, decide whether it is true or false. (2 points each) 1. Compilers run in the kernel mode. False 2. Only interrupts can change the CPU from user mode to kernel mode. True 3. Every interrupt changes the CPU from user mode to kernel mode. False 4. If there is only one CPU in the computer, then only one process can be in the ``running'' state at any time. True 5. The ``Shortest-Job-First'' policy always result in the lowest average waiting time in a batch system. True 6. The only way a process can change from the ``blocked'' state to the ``ready'' state is if an I/O operation finishes. False 7. Virtual memory location 0x1000 in Process A is different from virtual memory location 0x1000 in Process B. True 8. In Java, an exception is not an object. False 9. The CPU scheduling policy ``First-Come First-Served'' is the fairest policy, and always has the best performance. False 10. If a program uses only one semaphore, its threads will never get into a deadlock. False III. (15 points) A process, simply put, is a program in execution. 1. List all the possible states that a process can be in, and draw a state-transition diagram describing how a process moves among the states. (9 points) Answer: Check page p. 90 of the dinasour book, Figure 4.1. (Grading Criteria: Each state and each link counts for one point.) 2. Can a process issue a disk I/O when it is in the ``ready'' state? (2 points) No. 3. The kernel keeps a record for each process, called Process Control Block (PCB). When a process is not running, PCB contains the information that is necessary to restart the process on the CPU. List two pieces of information that the PCB must have. (4 points) Answer: program counter (2 points), CPU register (2 points), pointer to page table, CPU scheduling priority information, etc. V. (15 points) Suppose a computer has 4 physical pages, and a process references its virtual pages (page 0 through page 7) in the following order: 0 2 1 3 5 4 6 3 7 4 7 3 3 5 5 3 1 1 1 7 2 3 4 1 1. Suppose the kernel uses FIFO page replacement algorithm. How many page faults would the process have? Which page references are page faults? 2. Suppose the kernel uses LRU as the page replacement algorithm, answer the above two questions. 3. Suppose the kernel uses MIN (the optimal page replacement algorithm), answer the above two questions. Answer: 0 2 1 3 5 4 6 3 7 4 7 3 3 5 5 3 1 1 1 7 2 3 4 1 FIFO: ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ --> 13 page faults LRU: ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ --> 13 page faults MIN: ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ --> 10 page faults Grading: Each subquestion has 5 points. For each subquestion: . Compulsory page fault not counted: - 1 point. . page fault references are counted wrong: -0.5 for each mistake.