Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 143 Principles of Operating Systems

Similar presentations


Presentation on theme: "ICS 143 Principles of Operating Systems"— Presentation transcript:

1 ICS 143 Principles of Operating Systems
Discussion Section Week 7

2 Today Announcements Programming Assignment Homework #3 Lecture Review
Pop Quiz #2 11/17/2018

3 Announcements Programming Assignment Homework #2 scores out now
Due Wed, 10 June 2015, 11:55pm via EEE Dropbox Homework #2 scores out now Homework #1 scores will follow shortly Homework #3: Out now on class website Due Thu, 21 May 2015, 11:55pm via EEE Dropbox 11/17/2018

4 Programming Assignment
Assignment description has moved to GitHub: Scroll down to see README.md Check repo history frequently for updates: s/master 11/17/2018

5 Programming Assignment (2)
Input: text file One incoming process per line <process-id> <burst-time> <arrival-time> <share> <process-id> <arrival-time> <burst-time> <share> Output: text file One scheduled process per line <process-id> <finish-time> <wait-time> <turnaround- time> Last line: <average-wait-time> <average-turnaround-time> 11/17/2018

6 Programming Assignment (3)
Other updates: New assumption for Proportional Share (PS) scheduler: If PID 3 with share 60 and PID4 with share 10 are in ready queue at the same time, then PID 3 must be scheduled first. Please take a look at `ps5.input` and `ps5.expected` for a complete example. Time limit: Each test must finish within **2.1 seconds**. After that time, timeout will occur and that test will be assumed to have failed. All updates will appear in repo history 11/17/2018

7 Deadlocks A process is deadlocked if
it is waiting for an event that will never occur A process is indefinitely postponed if it is delayed repeatedly over a long period of time while the attention of the system is given to other processes 11/17/2018

8 Resources Resource: commodity required by a process to execute
Serially reusable resources CPU cycles, memory space, I/O devices, files Acquire => use => release Consumable resources Messages, buffers of information, interrupts Create => acquire => use Resource ceases to exist after it has been used 11/17/2018

9 Deadlock Conditions Necessary and sufficient conditions for deadlock to occur (must hold simultaneously): Mutual exclusion Only one process at a time can use the resource Hold and wait Processes hold resources already allocated to them while waiting for other resources No preemption Resources are released by processes holding them only after that process has completed its task Circular wait A circular chain of processes exists in which each process waits for one or more resources held by the next process in the chain. 11/17/2018

10 Resource Allocation Graph
Process: Resource type with 4 instances: Pi requests instance of Rj: Pi is holding instance of Rj: Deadlock?? 11/17/2018

11 Deadlocks in Resource Allocation Graphs
If graph contains no cycles: NO DEADLOCK If graph contains a cycle: If only one instance per resource type, then deadlock If several instances per resource type, possibility of a deadlock 11/17/2018

12 Deadlock Management Deadlock detection Deadlock avoidance
Allow possibility of a deadlock, determine if deadlock has occurred and which processes and resources are involved Deadlock avoidance Allow possibility of a deadlock, but sidestep it as it occurs Deadlock recovery Allow possibility of a deadlock, detect it; then clear the problem, allowing processes to complete and resources to be reused Deadlock prevention Design the system in such a way that deadlocks can never occur 11/17/2018

13 Deadlock Prevention How to prevent deadlock?
If any of the conditions for deadlock is denied, deadlock is impossible Mutual exclusion: Allow multiple processes to access shared resources at the same time Hold and wait: Guarantee that when a process requests a resource, it does not hold other resources No preemption: Release resources instead of waiting for process completion Circular wait: Require that processes request resources in increasing order: if process holds resource of type N, can only request types > N Price to be paid: reduced performance (overhead), allow data corruption, etc. 11/17/2018

14 Deadlock Avoidance Banker’s algorithm (Dijkstra):
Set of resources, set of customers, banker Each customer tells banker maximum number of resources it needs Customer borrows resources from banker Customer returns resources to banker Customer eventually pays back loan Banker only lends resources if the system will be in a safe state after the loan 11/17/2018

15 Safe State System is in a safe state if there exists a safe sequence of all processes Sequence <P1, P2, …, Pn> is safe if for each Pi: the resources that Pi can still request can be satisfied with currently available resources and resources held by Pj with j<I If system is in a safe state: NO DEADLOCK If system is in an unsafe state: possibility of deadlock 11/17/2018

16 Banker’s Algorithm Allocation: How many instances of each resource type a process is currently holding Max: The maximum number of resource instances (per resource type) a process may request Available: How many instances of each resource type are currently available 11/17/2018

17 Banker’s Algorithm (2) Need: How many more instances of each resource type a process needs to complete Need[i,j] = Max[i,j] – Allocation[i,j] For process i and resource type j 11/17/2018

18 Banker’s Algorithm (3) ? ≤
Consider P1 requesting (1,0,2). Can the request be granted? Need to make sure Request ≤ Available Request A B C ? 11/17/2018

19 Banker’s Algorithm (4) Is the system in a safe state? If yes, give a safe sequence. Can I run P0? P1? P2? P3? P4? E.g.: Run P1: etc. … 11/17/2018

20 Deadlock Detection Allow system to enter deadlock state
Detection Algorithm: Periodically invoke an algorithm that searches for a cycle in the graph, but O(n^2)! Detect unsafe sequence via Banker’s algorithm How often to check? Every time a request for allocation cannot be granted immediately Every hour or whenever CPU utilization drops etc. 11/17/2018

21 Deadlock Recovery How to recover from deadlock:
Abort all deadlocked processes Abort one process at a time until deadlock cycle is eliminated In which order should we choose to abort? Select a victim: minimize cost Priority of the process Resources used by process Resources needed by process to complete How many processes will need to be terminated Rollback: return to some safe state, restart process from that state Starvation possible? Yes, same process may always be picked as victim. Fix: Include number of rollback in cost factor 11/17/2018

22 ? Memory Management First-fit: Best-fit: Worst-fit:
Allocate the first hole that is big enough Best-fit: Allocate the smallest hole that is big enough Must search entire list, unless ordered in size Worst-fit: Allocate the largest hole Must search entire list First-fit and best-fit are better than worst-fit in terms of speed and storage utilization P0 requests 200KB Main Memory 500KB free ? 780KB free 250KB free 150KB free 11/17/2018

23 Pop Quiz #2 11/17/2018


Download ppt "ICS 143 Principles of Operating Systems"

Similar presentations


Ads by Google