Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 153 Design of Operating Systems Spring 2015 Midterm Review.

Similar presentations


Presentation on theme: "CS 153 Design of Operating Systems Spring 2015 Midterm Review."— Presentation transcript:

1 CS 153 Design of Operating Systems Spring 2015 Midterm Review

2 2 Midterm l in class on Friday l Covers material through scheduling and deadlock l Based upon lecture material and Chapters 1 to 7 u Closed book. No additional sheets of notes

3 Project 2 is out today l Three weeks to complete l Do not count on extensions! 3

4 4 Overview l Architectural support for Oses l Processes l Threads l Synchronization l Scheduling (including deadlock)

5 5 Arch Support for OSes l Types of architecture support u Manipulating privileged machine state u Generating and handling events

6 6 Privileged Instructions l What are privileged instructions? u Who gets to execute them? u How does the CPU know whether they can be executed? u Difference between user and kernel mode l Why do they need to be privileged? l What do they manipulate? u Protected control registers u Memory management u I/O devices

7 7 Events l Events u Synchronous: faults (exceptions), system calls u Asynchronous: interrupts l What are faults, and how are they handled? l What are system calls, and how are they handled? l What are interrupts, and how are they handled? u How do I/O devices use interrupts? l What is the difference between exceptions and interrupts?

8 8 Processes l What is a process? l What resource does it virtualize? l What is the difference between a process and a program? l What is contained in a process?

9 9 Process Data Structures l Process Control Blocks (PCBs) u What information does it contain? u How is it used in a context switch? l State queues u What are process states? u What is the process state graph? u When does a process change state? u How does the OS use queues to keep track of processes?

10 10 Process Manipulation l What does CreateProcess on Windows do? l What does fork() on Unix do? u What does it mean for it to “return twice”? l What does exec() on Unix do? u How is it different from fork? l How are fork and exec used to implement shells?

11 11 Threads l What is a thread? u What is the difference between a thread and a process? u How are they related? l Why are threads useful? l What is the difference between user-level and kernel- level threads? u What are the advantages/disadvantages of one over another?

12 12 Thread Implementation l How are threads managed by the run-time system? u Thread control blocks, thread queues u How is this different from process management? l What operations do threads support? u Fork, yield, sleep, etc. u What does thread yield do? l What is a context switch? l What is the difference between non-preemptive scheduling and preemptive thread scheduling? u Voluntary and involuntary context switches

13 13 Synchronization l Why do we need synchronization? u Coordinate access to shared data structures u Coordinate thread/process execution l What can happen to shared data structures if synchronization is not used? u Race condition u Corruption u Bank account example l When are resources shared? u Global variables, static objects u Heap objects

14 14 Mutual Exclusion l What is mutual exclusion? l What is a critical section? u What guarantees do critical sections provide? u What are the requirements of critical sections? »Mutual exclusion (safety) »Progress (liveness) »Bounded waiting (no starvation: liveness) »Performance l How does mutual exclusion relate to critical sections? l What are the mechanisms for building critical sections? u Locks, semaphores, monitors, condition variables

15 15 Locks l What does Acquire do? l What does Release do? l What does it mean for Acquire/Release to be atomic? l How can locks be implemented? u Spinlocks u Disable/enable interrupts l How does test-and-set work? u What kind of lock does it implement? l What are the limitations of using spinlocks, interrupts? u Inefficient, interrupts turned off too long

16 16 Semaphores l What is a semaphore? u What does Wait/P/Decrement do? u What does Signal/V/Increment do? u How does a semaphore differ from a lock? u What is the difference between a binary semaphore and a counting semaphore? l When do threads block on semaphores? l When are they woken up again? l Using semaphores to solve synchronization problems u Readers/Writers problem u Bounded Buffers problem

17 17 Monitors l What is a monitor? u Shared data u Procedures u Synchronization l In what way does a monitor provide mutual exclusion? u To what extent is it provided? l How does a monitor differ from a semaphore? l How does a monitor differ from a lock? l What kind of support do monitors require? u Language, run-time support

18 18 Condition Variables l What is a condition variable used for? u Coordinating the execution of threads u Not mutual exclusion l Operations u What are the semantics of Wait? u What are the semantics of Signal? u What are the semantics of Broadcast? l How are condition variables different from semaphores?

19 19 Implementing Monitors l What does the implementation of a monitor look like? u Shared data u Procedures u A lock for mutual exclusion to procedures (w/ a queue) u Queues for the condition variables l What is the difference between Hoare and Mesa monitors? u Semantics of signal (whether the woken up waiter gets to run immediately or not) u What are their tradeoffs? u What does Java provide?

20 20 Scheduling l What kinds of scheduling is there? u Long-term scheduling u Short-term scheduling l Components u Scheduler (dispatcher) l When does scheduling happen? u Job changes state (e.g., waiting to running) u Interrupt, exception u Job creation, termination

21 21 Scheduling Goals l Goals u Maximize CPU utilization u Maximize job throughput u Minimize turnaround time u Minimize waiting time u Minimize response time l What is the goal of a batch system? l What is the goal of an interactive system?

22 22 Starvation l Starvation u Indefinite denial of a resource (CPU, lock) l Causes u Side effect of scheduling u Side effect of synchronization l Operating systems try to prevent starvation

23 23 Scheduling Algorithms l What are the properties, advantages and disadvantages of the following scheduling algorithms? u First Come First Serve (FCFS)/First In First Out (FIFO) u Shortest Job First (SJF) u Priority u Round Robin u Multilevel feedback queues l What scheduling algorithm does Unix use? Why?

24 24 Deadlock l Deadlock happens when processes are waiting on each other and cannot make progress l What are the conditions for deadlock? u Mutual exclusion u Hold and wait u No preemption u Circular wait l How to visualize, represent abstractly? u Resource allocation graph (RAG) u Waits for graph (WFG) P1 P2 P3 P1 P2 P3 R1 R2 R3

25 25 Deadlock Approaches l Dealing with deadlock u Ignore it u Detect and recover from it u Prevent it (prevent one of the four conditions) u Avoid it (have tight control over resource allocation) l What is the Banker’s algorithm? u Which of the four approaches above does it implement?

26 Question 1 l Most operating systems are designed for general-purpose computation. A proposal has been put forth for an OS that is optimized for running math-intensive programs. In MathOS, the kernel includes system calls for many useful mathematical operations, such as matrix arithmetic, Bessel functions, Euclidean distance, etc. These system calls are written in highly optimized assembly language for maximum performance. Is this concept for MathOS a good idea? Explain why or why not. l No! Math functions won’t benefit from running in the kernel. They do not need privileged instructions or special facilities. You’re putting crap in the kernel that has no reason to be there. Moreover: The overhead of calling them: mode switch + data copy is more time-consuming than a function call 26

27 Question 2 l What is the difference between a mode switch and a context switch? l Mode switch: change CPU execution mode from one privilege level to another e.g., user → kernel via a trap or syscall. l Context switch: save one process’ execution context & restore that of another process 27

28 Question 3 l What is the similarity and difference between faults (exceptions) and interrupts? l Both are unexpected, yet l Faults are synchronous l Interrupts are asynchronous 28

29 Question 4 l List two events that may take a process to a ready state. l Startup: created → ready l Preemption: running → ready l I/O complete: blocked → ready 29

30 Question 5 l Given that we can create user-level code to control access to critical sections (e.g., Peterson’s algorithm), why is it important for an operating system to provide synchronization facilities such as semaphores in the kernel? l Question is about offering sync services via the kernel than via user-level code. l To avoid busy waiting: the waiting thread can go to sleep u creates better CPU utilization; avoids priority inversion (if an issue) 30

31 Question 6 l What does a time-sharing system need that a multiprogramming system does not? (a) Trap mechanism (b) Kernel mode execution privileges (c) Shorter time slices (d) Interval Timer (d) 31

32 Question 7 l When does preemption take place? (a) When a quantum expires. (b) When a process issues an I/O request. (c) When a process exits. (d) All of the above. (a) 32

33 Question 8 l What information is stored in a thread control block (TCB)? (a) List of open files. (b) Stack pointer. (c) Memory map. (d) Thread owner ID. (b) 33

34 Question 9 l A test-and-set instruction allows you to: (a) Modify a memory location only if its contents match a given value. (b) Exchange the contents of two memory locations if their values are different. (c) Exchange the contents of two memory locations if a lock is not set. (d) Exchange the contents of two memory locations if a lock is set. (a) 34

35 Question 10 l A thread that is blocked on a semaphore is awakened when another thread: (a) Tries to decrement a semaphore’s value below 0. (b) Tries to increment the semaphore. (c) Causes the semaphore’s value to reach a specific number. (d) Tries to block on the same semaphore (b) 35

36 Question 11 l Switching among threads in the same process is more efficient than switching among processes. True of false? l True 36

37 Question 12 l The value of a semaphore can never be negative. True 37

38 Question 13 l Multilevel queues allow multiple processes to share the same priority level. True 38


Download ppt "CS 153 Design of Operating Systems Spring 2015 Midterm Review."

Similar presentations


Ads by Google