Powered By Blogger

Aug 12, 2024

Example on SJF CPU Scheduling algorithm

Evaluate SJF CPU Scheduling algorithm for given Problem , Find Average Turn Around Time and Average Response Time  

Process

P1

P2

P3

P4

Process Time

8

4

9

5

Arrival Time

0

1

2

3


Given:

  • Processes:
    • P1: Burst Time = 8 ms, Arrival Time = 0 ms
    • P2: Burst Time = 4 ms, Arrival Time = 1 ms
    • P3: Burst Time = 9 ms, Arrival Time = 2 ms
    • P4: Burst Time = 5 ms, Arrival Time = 3 ms

Step 1: Process Execution Order

The SJF algorithm selects the process with the shortest burst time that has arrived and is ready to execute. If two processes have the same burst time, the one that arrived earlier is selected.

Order of Execution:

  1. P1 arrives at 0 ms, and it starts execution immediately since it's the only process available.
  2. P2 arrives at 1 ms and has the shortest burst time after P1 finishes.
  3. P4 arrives at 3 ms and has the shortest burst time after P2 finishes.
  4. P3 arrives at 2 ms but has the longest burst time, so it is executed last.

Step 2: Completion Time (CT), Turnaround Time (TAT), and Response Time (RT)

  • Completion Time (CT): The time at which each process completes its execution.
  • Turnaround Time (TAT): The total time taken from arrival to completion of a process.
    \text{TAT} = \text{Completion Time (CT)} - \text{Arrival Time (AT)}
  • Response Time (RT): The time from the arrival of the process until it starts executing.
    \text{RT} = \text{Start Time} - \text{Arrival Time (AT)}

Execution and Calculations


ProcessArrival Time (AT)Burst Time (BT)Start Time (ST)Completion Time (CT)Turnaround Time (TAT)Response Time (RT)
P10 ms8 ms0 ms8 ms8 ms0 ms
P21 ms4 ms8 ms12 ms11 ms7 ms
P43 ms5 ms12 ms17 ms14 ms9 ms
P32 ms9 ms17 ms26 ms24 ms15 ms

Step 3: Average Turnaround Time and Average Response Time

  • Average Turnaround Time (TAT):

    Average TAT=8+11+14+244=14.25 ms\text{Average TAT} = \frac{8 + 11 + 14 + 24}{4} = 14.25 \text{ ms}
  • Average Response Time (RT):

    Average RT=0+7+9+154=7.75 ms\text{Average RT} = \frac{0 + 7 + 9 + 15}{4} = 7.75 \text{ ms}
  • Order of Execution: P1, P2, P4, P3
  • Average Turnaround Time: 14.25 ms
  • Average Response Time: 7.75 ms

No comments:

Post a Comment

Featured Post

Data Analysis

    What is data analysis and its significance?   Data analysis is the process of collecting, transforming, and organizing data to dr...

Popular Posts