Cpu scheduling calculate with line, graphy, bar

Computer Science

ScanSolve AI Answer

Answer

4.25
7.75

CPU scheduling determines which process gets the CPU and for how long, aiming to optimize system performance. Here's how to calculate and visualize scheduling with an example.

Let's use the following processes:

ProcessArrival Time (AT)Burst Time (BT)
P105
P213
P322
P434

We will calculate:

  • Completion Time (CT): Time when a process finishes execution.
  • Turnaround Time (TAT): CT−ATCT - AT.
  • Waiting Time (WT): TAT−BTTAT - BT.

1. First-Come, First-Served (FCFS)

Processes are executed in the order they arrive.

Gantt Chart:

| P1      | P2    | P3  | P4      |
0         5       8     10        14

Calculations:

  • P1:
    • Starts at 0, Finishes at 5
    • CT=5CT = 5
    • TAT=5−0=5TAT = 5 - 0 = 5
    • WT=5−5=0WT = 5 - 5 = 0
  • P2:
    • Starts at 5, Finishes at 5+3=85 + 3 = 8
    • CT=8CT = 8
    • TAT=8−1=7TAT = 8 - 1 = 7
    • WT=7−3=4WT = 7 - 3 = 4
  • P3:
    • Starts at 8, Finishes at 8+2=108 + 2 = 10
    • CT=10CT = 10
    • TAT=10−2=8TAT = 10 - 2 = 8
    • WT=8−2=6WT = 8 - 2 = 6
  • P4:
    • Starts at 10, Finishes at 10+4=1410 + 4 = 14
    • CT=14CT = 14
    • TAT=14−3=11TAT = 14 - 3 = 11
    • WT=11−4=7WT = 11 - 4 = 7

Average Metrics:

Average Waiting Time=0+4+6+74=174=4.25\text{Average Waiting Time} = \frac{0 + 4 + 6 + 7}{4} = \frac{17}{4} = \boxed{4.25} Average Turnaround Time=5+7+8+114=314=7.75\text{Average Turnaround Time} = \frac{5 + 7 + 8 + 11}{4} = \frac{31}{4} = \boxed{7.75}

2. Shortest Job First (SJF) - Non-Preemptive

The process with the shortest burst time among the available processes is executed next.

Gantt Chart:

| P1      | P3  | P2    | P4      |
0         5     7       10        14

Calculations:

  • P1: (Only process at AT=0)
    • Starts at 0, Finishes at 5
    • CT=5CT = 5
    • TAT=5−0=5TAT = 5 - 0 = 5
    • WT=5−5=0WT = 5 - 5 = 0
  • P3: (At time 5, P2, P3, P4 are available. P3 has BT=2, which is shortest)
    • Starts at 5, Finishes at 5+2=75 + 2 = 7
    • CT=7CT = 7
    • TAT=7−2=5TAT = 7 - 2 = 5
    • WT=5−2=3WT = 5 - 2 = 3
  • P2: (At time 7, P2, P4 are available. P2 has BT=3, which is shortest)
    • Starts at 7, Finishes at 7+3=107 + 3 = 10
    • CT=10CT = 10
    • TAT=10−1=9TAT = 10 - 1 = 9
    • WT=9−3=6WT = 9 - 3 = 6
  • P4: (At time 10, only P4 is available)
    • Starts at 10
Was this helpful?

Try one yourself

A new problem that tests the same skill.

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question