0% found this document useful (0 votes)
13 views7 pages

Os Assignment 2 Copy 2

The document outlines various CPU scheduling algorithms including Shortest Job First (SJF), First Come First Serve (FCFS), Shortest Remaining Job First (SRJF), Round Robin (RR), and Priority Scheduling, detailing their characteristics, examples, and execution orders. It also discusses key process scheduling terms such as Completion Time, Average Turnaround Time, Average Waiting Time, and Response Time, providing formulas and examples for each. Additionally, it compares preemptive and non-preemptive scheduling, highlighting their efficiency and practical applications.

Uploaded by

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

Os Assignment 2 Copy 2

The document outlines various CPU scheduling algorithms including Shortest Job First (SJF), First Come First Serve (FCFS), Shortest Remaining Job First (SRJF), Round Robin (RR), and Priority Scheduling, detailing their characteristics, examples, and execution orders. It also discusses key process scheduling terms such as Completion Time, Average Turnaround Time, Average Waiting Time, and Response Time, providing formulas and examples for each. Additionally, it compares preemptive and non-preemptive scheduling, highlighting their efficiency and practical applications.

Uploaded by

bushrafayyaz252
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Shortest Job First (SJF) Scheduling Algorithm

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.

Real-Life Examples of SJF:

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.

Example Execution Order:

Processes with burst times:


P1 = 9ms, P2 = 5ms, P3 = 3ms, P4 = 1ms
Execution follows: P4 → P3 → P2 → P1

2. First Come First Serve (FCFS) Scheduling Algorithm

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?

• Non-Preemptive: Once a process starts execution, it cannot be stopped until it


completes, even if a higher-priority or shorter process arrives later.

Real-Life Examples of FCFS:

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.

Example Execution Order:

Processes arriving in order P1, P2, P3 execute in the same order, regardless of burst times.

3. Shortest Remaining Job First (SRJF) Algorithm

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.

Real-Life Examples of SRJF:

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.

Example Execution Order:

Processes with remaining burst times:


P1 = 7ms, P2 = 4ms, P3 = 2ms
Execution dynamically switches to the process with the shortest remaining time.

4. Round Robin (RR) Scheduling Algorithm

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.

Real-Life Examples of Round Robin:

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.

Example Execution Order (Time Quantum = 3ms):

For P1 = 6ms, P2 = 5ms, P3 = 3ms, execution follows:


P1 (3ms) → P2 (3ms) → P3 (3ms) → P1 (3ms) → P2 (2ms)

5. Priority Scheduling Algorithm

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?

• Preemptive: A higher priority process can interrupt the current execution.


• Non-Preemptive: A running process cannot be interrupted, even if a higher-priority
process arrives.

Real-Life Examples of Priority Scheduling:

• Emergency Calls: 911 calls are handled before regular calls.


• Hospital ICU: Critical patients receive treatment before less severe cases.
• Operating Systems: Important system updates execute before background processes.
• Air Traffic Control: Landing planes are prioritized over departing ones.

Example Execution Order (Higher number = Higher Priority):

If we have P1 (Priority 2), P2 (Priority 4), P3 (Priority 1),


Execution follows: P2 → P1 → P3 (since P2 has the highest priority).

6. Preemptive vs. Non-Preemptive Scheduling


Feature Preemptive Scheduling Non-Preemptive Scheduling
Process Allowed (Higher priority process Not Allowed (Once a process starts, it runs
Interruption can interrupt) till completion)
Example Round Robin, SRJF, Preemptive FCFS, Non-Preemptive SJF, Non-Preemptive
Algorithms Priority Priority
Efficiency Better CPU utilization Simple but may cause delays
Example Multitasking in OS (switching Printing documents in order
between apps)

Process Scheduling Terms


gantt chart aisey bnay ge sbke

A. Completion Time (CT)


The Completion Time (CT) of a process refers to the exact time when a process finishes its
execution and exits the system. It indicates the moment at which the CPU has completely
processed a given task. Completion time is crucial in evaluating a scheduling algorithm's
efficiency, as lower CT values contribute to better system performance.

Examples of Completion Time:

1. A file finishes downloading at 3:00 PM.


2. A student submits an assignment at 5:30 PM.
3. A printer finishes printing a document at 2:15 PM.

Process Table for CT Calculation

Process Arrival Time Burst Time Completion Time


P1 0 4 4
P2 1 3 7
P3 2 5 12

Gantt Chart for Completion Time


Time 0 4 7 12
Process P1 P2 P3
Waiting Time Calculation for CT

• P1 = 0
• P2 = 4 - 1 = 3
• P3 = 7 - 2 = 5

Average Waiting Time = (0 + 3 + 5) / 3 = 2.67

B. Average Turnaround Time (ATAT)


The Turnaround Time (TAT) of a process is the total time spent in the system from its arrival to
its completion. It includes both execution time and waiting time. A lower TAT means that
processes are completed faster, improving overall system responsiveness.

Formula:

TAT=CompletionTime−ArrivalTimeTAT = Completion Time - Arrival Time

Examples of Turnaround Time:

1. A pizza order placed at 5:00 PM is delivered at 5:30 PM (TAT = 30 min).


2. A movie downloaded at 2:00 PM finishes at 2:45 PM (TAT = 45 min).
3. A customer in a bank arrives at 10:00 AM and leaves at 10:20 AM (TAT = 20 min).

Process Table for TAT Calculation

Process Arrival Time Burst Time Completion Time Turnaround Time


P1 0 3 5 5
P2 1 4 10 9
P3 2 2 7 5

Gantt Chart for Turnaround Time


Time 0 3 5 7 10
Process P1 P3 P2

Waiting Time Calculation for ATAT

• P1 = 0
• P2 = 5
• P3 = 7 - 2 = 5

Average Waiting Time = (0 + 5 + 5) / 3 = 3.33


C. Average Waiting Time (AWT)
Waiting Time (WT) is the total time a process spends in the ready queue before getting executed.
It does not include the time spent in execution but only the idle time before execution starts. A
lower waiting time improves CPU efficiency and process responsiveness.

Formula:

WT=TurnaroundTime−BurstTimeWT = Turnaround Time - Burst Time

Examples of Waiting Time:

1. A customer waits 10 minutes for a bus before it arrives.


2. A student waits 15 minutes before their turn in an oral exam.
3. A patient in a hospital waits 20 minutes before a doctor sees them.

Process Table for WT Calculation

Process Arrival Time Burst Time Turnaround Time Waiting Time


P1 0 4 8 4
P2 1 3 7 4
P3 2 5 10 5

Gantt Chart for Waiting Time


Time 0 4 7 10
Process P1 P2 P3

Waiting Time Calculation for AWT

• P1 = 0
• P2 = 24
• P3 = 27

Average Waiting Time = (0 + 24 + 27) / 3 = 17

D. Response Time (RT)


Response Time (RT) is the time taken by the CPU to start executing a process after it arrives in
the ready queue. It measures the system's responsiveness and plays a crucial role in user
experience for interactive systems. Lower response times lead to better system performance.
Formula:

RT=FirstResponseTime−ArrivalTimeRT = First Response Time - Arrival Time

Examples of Response Time:

1. When you click on an app, it takes 2 seconds to open.


2. A car takes 5 seconds to accelerate after pressing the pedal.
3. A website loads in 3 seconds after clicking the link.

Process Table for RT Calculation

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

Gantt Chart for Response Time


Time 0 3 7 9
Process P1 P2 P3

Waiting Time Calculation for RT

• P1 = 0
• P2 = 24
• P3 = 27

Average Waiting Time = (0 + 24 + 27) / 3 = 17

You might also like