OS ch 5

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

11 Terms

1
New cards

Consequences of Poor Synchronization

  • Deadlock: Two processes stuck waiting for each other.

  • Livelock: Two processes keep reacting to each other but don’t make progress.

  • Starvation: A process waits forever because resources never free up.

2
New cards

Deadlock affects

  • the whole system, not just one job. Worse in real-time systems.

3
New cards

Modeling Deadlocks with Directed Graphs

  • Circle = process, Square = resource.

  • Solid arrow: Resource held by process.

  • Dashed arrow: Process waiting for resource.

  • Cycle in graph = deadlock!

4
New cards

Examples of Deadlocks

  • File Requests: Two programs need each other’s files = deadlock.

  • Databases: Two users lock records and wait for each other.

  • Dedicated Device Allocation: Two processes want two devices but get blocked.

  • Multiple Devices: 3 programs each waiting on a different device (scanner, printer, plotter).

  • Spooling: Not enough disk space for printer jobs = deadlock.

  • Disk Sharing (Livelock): Disk arm moves back and forth endlessly.

5
New cards

Conditions for Deadlock

  • Mutual Exclusion: Only one process can use a resource at a time.

  • Resource Holding: Hold one resource, wait for another.

  • No Preemption: Can't take resources back.

  • Circular Wait: Chain of processes each waiting for another.

6
New cards

Deadlock Detection Using Graphs

  • If there’s a cycledeadlock.

  • If you can reduce the graph by removing finished processes → no deadlock.

7
New cards

Strategies to Handle Deadlocks First Step

Prevention

  • Mutual exclusion: Share resources (e.g., spooling printers).

  • Resource holding: Request all resources at once.

  • No preemption: Allow OS to take back resources.

  • Circular wait: Order resources so they’re requested in a sequence.

8
New cards

Strategies to Handle Deadlocks Second Step

Avoidance

  • Use Banker’s Algorithm (Dijkstra, 1965):

    • Like lending money: don't give out resources unless it's safe.

    • Avoid unsafe states where deadlock might happen.

9
New cards

Strategies to Handle Deadlocks Third Step

Detection

  • Build graphs.

  • Detect cycles.

  • If deadlock → recover.

10
New cards

Strategies to Handle Deadlocks Fourth Step

Recovery

  • Terminate all jobs (extreme!).

  • Terminate only involved jobs.

  • Preempt resources from non-deadlocked jobs.

  • Choose a victim based on least damage (ex: don't kill high-priority jobs).

11
New cards

Starvation

  • A job never gets resources.

  • Happens due to very cautious resource allocation.

  • Solution: Aging — gradually increase priority the longer a job waits.

Example: Dining Philosophers Problem — if one philosopher never gets two forks, they starve.