0% found this document useful (0 votes)
6 views6 pages

Understanding Deadlock and CPU Scheduling

Deadlock occurs when processes are unable to proceed because each is waiting for resources held by the other, resulting in a standstill. There are various types of deadlock, including resource, communication, system, and application deadlocks, all of which require four specific conditions to occur. CPU scheduling is crucial for optimizing CPU utilization and system performance, with several algorithms available, such as FCFS, SJF, and Round Robin, each having its own advantages and disadvantages.

Uploaded by

ashiratiq5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Understanding Deadlock and CPU Scheduling

Deadlock occurs when processes are unable to proceed because each is waiting for resources held by the other, resulting in a standstill. There are various types of deadlock, including resource, communication, system, and application deadlocks, all of which require four specific conditions to occur. CPU scheduling is crucial for optimizing CPU utilization and system performance, with several algorithms available, such as FCFS, SJF, and Round Robin, each having its own advantages and disadvantages.

Uploaded by

ashiratiq5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DEAD LOCK:

1️⃣ What is Deadlock?


Deadlock is a situation where two or more processes stop working because each one is
waiting for the other to release a resource.

👉 Result: No process can continue.

Simple example:
Process A has File and wants Printer
Process B has Printer and wants File
Both wait forever → Deadlock

2️⃣ Types of Deadlock


🔹 1. Resource Deadlock

Happens when processes wait for resources (printer, memory, file).

🔹 2. Communication Deadlock

Happens when processes wait for messages from each other and no one sends.

3️⃣ Resources of Deadlock


Resources that cause deadlock:

 Printer
 Scanner
 File
 Memory
 CPU
 Network connection

👉 When resources are limited, deadlock can happen.


4️⃣ Communication Deadlock
When:

 Process A waits for a message from Process B


 Process B waits for a message from Process A

Both wait forever → Communication Deadlock

5️⃣ System Deadlock


System deadlock happens when important system resources are blocked.

👉 Whole system becomes slow or frozen.

Example:

 Multiple programs waiting for CPU and memory


 OS cannot continue normal work

6️⃣ Application Deadlock


Happens inside a program or software.

Example:

 One thread locks File A and waits for File B


 Another thread locks File B and waits for File A

👉 Application freezes.

7️⃣ Conditions of Deadlock (Very Important) ⭐


Deadlock happens only if all 4 conditions exist:

1️⃣ Mutual Exclusion


Only one process can use a resource at a time.
2️⃣ Hold and Wait
Process holds one resource and waits for another.

3️⃣ No Preemption
Resource cannot be taken forcefully.

4️⃣ Circular Wait


Processes wait in a circle.

👉 If any one condition is removed, deadlock will NOT happen.

8️⃣ One-Line Summary (For Exams)


Deadlock is a situation where processes wait forever for resources held by each other due to
mutual exclusion, hold and wait, no preemption, and circular wait.

CPU Scheduling :

What is CPU Scheduling?


CPU Scheduling is the method used by the Operating System to decide which process will use
the CPU next.

👉 Because many processes want CPU at the same time, OS must choose one.

Why CPU Scheduling is Important?


 Improves CPU utilization
 Reduces waiting time
 Improves system performance
 Allows multitasking

Types of CPU Scheduling


🔹 1. Non-Preemptive Scheduling
CPU is not taken back until the process finishes.

🔹 2. Preemptive Scheduling

CPU can be taken back and given to another process.

CPU Scheduling Algorithms (Easy Explanation)


1️⃣ First Come First Serve (FCFS)

 Process comes first → gets CPU first


 Simple but causes long waiting time

Example:
P1 → P2 → P3

2️⃣ Shortest Job First (SJF)

 Process with smallest execution time runs first


 Gives minimum waiting time

❌ Difficult to know burst time in advance

3️⃣ Priority Scheduling

 Process with highest priority runs first


 Low priority process may starve

4️⃣ Round Robin (RR)

 Each process gets fixed time (time quantum)


 After time ends, next process runs

✔ Used in time-sharing systems


5️⃣ Multilevel Queue Scheduling

 Ready queue is divided into multiple queues


 Each queue has its own algorithm

6️⃣ Multilevel Feedback Queue

 Process can move between queues


 Prevents starvation

Comparison Table (Very Simple)


Algorithm Preemptive Advantage Disadvantage
FCFS No Simple Long waiting
SJF Yes/No Fast Burst time unknown
Priority Yes/No Important jobs first Starvation
Round Robin Yes Fair Time overhead

One-Line Exam Notes 📝


 FCFS: First come first serve
 SJF: Shortest job runs first
 Priority: High priority first
 RR: Fixed time for each process

Quick Tip for Exams ⭐


If question asks:

 Minimum waiting time → SJF


 Time sharing system → Round Robin
 Simple scheduling → FCFS

You might also like