Os Assignment 2 Copy 2
Os Assignment 2 Copy 2
SJF is a CPU scheduling algorithm that selects the process with the shortest execution time
(burst time) to run first. The primary goal of SJF is to reduce the waiting time of processes and
increase overall system efficiency. By prioritizing shorter processes, the algorithm ensures that
small tasks are completed quickly, leading to better responsiveness and lower turnaround times.
Preemptive or Non-Preemptive?
• Non-Preemptive SJF: Once a process starts executing, it runs until completion without
interruption, even if a shorter process arrives.
• Preemptive SJF (Shortest Remaining Job First - SRJF): If a shorter job arrives while
another is running, it interrupts the current process and executes immediately.
1. Car Wash: A small car gets cleaned before an SUV because it takes less time.
2. Grocery Billing: A person with fewer items gets checked out before someone with a full
cart.
3. Restaurant Orders: A single coffee order is served before a large meal.
4. Photo Printing: A passport-sized photo prints before a large poster.
FCFS is the simplest CPU scheduling algorithm, where processes are executed in the order
they arrive. It operates just like a queue: the first process to enter the queue is the first to be
executed. The simplicity of this algorithm makes it easy to implement, but it can lead to long
waiting times for processes that arrive later.
Preemptive or Non-Preemptive?
1. Bus Stop: The first passenger in line boards the bus first.
2. Library Book Issue: The first student in line gets the book first.
3. ATM Queue: The first person at an ATM completes their transaction before the next.
4. Elevator Use: The first person pressing the button is served first.
Processes arriving in order P1, P2, P3 execute in the same order, regardless of burst times.
SRJF is a Preemptive version of SJF, meaning that the currently running process can be
interrupted if a newer process with a shorter remaining time arrives. This ensures that small
tasks finish quickly, improving system responsiveness.
Preemptive or Non-Preemptive?
• Preemptive: If a process with a shorter remaining time arrives, it will interrupt the
current execution and take over the CPU.
1. Emergency Ward: A mild fever patient may wait if a critical patient arrives.
2. Cash Counter: A single-item buyer is checked out before a cart full of groceries.
3. Home Repairs: A quick door fix is done before a major plumbing repair.
4. Software Updates: A small security patch installs before a large OS update.
Round Robin is a fair CPU scheduling algorithm that assigns each process an equal time slice
(time quantum). Once a process reaches its allotted time, it moves to the back of the queue,
allowing other processes to execute.
Preemptive or Non-Preemptive?
• Preemptive: Every process runs for a fixed time and is then interrupted, even if it hasn't
finished.
1. Playground Swings: Each child gets equal playtime before giving another a turn.
2. Group Discussion: Each person gets a fixed speaking time before passing the turn.
3. Office Meetings: Each employee presents for 5 minutes before the next takes over.
4. Video Streaming: Multiple users sharing a slow internet connection get bandwidth in
turns.
Priority Scheduling assigns each process a priority number, and the process with the highest
priority gets executed first. If two processes have the same priority, they follow FCFS.
Preemptive or Non-Preemptive?
• P1 = 0
• P2 = 4 - 1 = 3
• P3 = 7 - 2 = 5
Formula:
• P1 = 0
• P2 = 5
• P3 = 7 - 2 = 5
Formula:
• P1 = 0
• P2 = 24
• P3 = 27
Process Arrival Time Burst Time First Response Time Response Time
P1 0 3 0 0
P2 1 4 3 2
P3 2 2 7 5
• P1 = 0
• P2 = 24
• P3 = 27