CSOPESY_processes_05 - Scheduling Non-Preemptive, Priority Scheduling, Multilevel Queue, Thread, Multiprocessor

5 Scheduling Criteria

Scheduling Algorithm Non-Preemptive

First Come First Served

whatever arrives first completes before anything else

_attachments/Pasted image 20251008142251.png
_attachments/Pasted image 20251008142558.png

Shortest Job first

_attachments/Pasted image 20251008143717.png

Exponential Average

just use the formula
_attachments/Pasted image 20251008143655.png

τn+1=αtn+(1α)τn

_attachments/Pasted image 20251008175658.png

showing its a weighted formula:

if α=0τn+1=τn+(10)τnτn+1=+(1)τn more value predictionif α=1τn+1=(1)τn+(11)τnτn+1=taun+0τn+1=τnmore value control

so how do we compute?
_attachments/Pasted image 20251008180816.png

if our guess τn=10and α=0.5τn+1=τn+(1α)τnτn+1=0.5(6)+(1.5)(10)τn+1=3+5=8

note: the next actual CPU burst is 4...

previously, we got τn=8τn+1=τn+(1α)τnτn+1=0.5(4)+(10.5)(8)the 8 came from the previous predictionτn+1=2+4=6

There are other scheduling algorithms that are pre-emptive

Shortest Remaining Time First or Pre-emptive Shortest Job First

NOTE: THIS IS PREEMPTIVE
always chooses the process with the shortest remaining time for completion

Pre-emptive (GPT)

Preemptive means that the operating system’s scheduler can interrupt (or stop) a currently running process in order to give the CPU to another process that has higher priority (or a shorter burst time, depending on the scheduling algorithm).

Neso Academy SJF: https://www.youtube.com/watch?v=lpM14aWgl3Q

whiteboard at 30:51

34:10

_attachments/Pasted image 20251008203659.png
_attachments/Pasted image 20251008203836.png

Round Robin

_attachments/Pasted image 20251008204929.png

Priority Scheduling

_attachments/Pasted image 20251008211228.png
45:08

Priority Scheduling with Round Robin

_attachments/Pasted image 20251008213004.png
Time Quantum TQ=2

  1. at T=0, P4 has priority 1, executes for BT=7
  2. at T=0+7=7, P2 and P3 have priority 1, P2 executes w/ BT=5-TQ
    so BT=5-2=3
  3. at T=7+2=9, P2 is preempted, P3 executes w/ BT=8-2=6
  4. at T=9+2=11, P3 is preempted, P2 resumes w/ BT=3-2=1
  5. at T=11+2=13, P2 is preempted, P3 resumes w/ BT=6-2=4
  6. at T=13+2=15, P3 is preempted, P2 finishes w/ BT=1
  7. at T=15+1=16, P2 is done so P3 resumes w/ BT=4
  8. at T=16+4=20, P3 finishes and move on to P1 and P5 w/ priority 3
    at T=20, P1 executes w/ BT=4
  9. at T=20+2=22, P1 is preempted w/ BT=4-2=2, P5 executes w/ BT=3
  10. at T=22+2=24, P5 is preempted w/ BT=3-2=1, P1 resumes w/ BT=2
  11. at T=24+2=26, P1 finishes execution w/ BT=2-2=0, P5 resumes and finishes

Multilevel Queue and Multilevel Feedback Queue

Multilevel Queue Scheduling

each can have their own priority and scheduling algorithm
_attachments/Pasted image 20251008215614.png

Multi-level Feedback Queue (MLFQ)

Multilevel feedback queue mechanism
_attachments/Pasted image 20251008215405.png

Thread Scheduling

user level is PCS
kernel level is SCS

Multi-Processor Scheduling

OS Examples

_attachments/Pasted image 20251008221353.png

Summary

_attachments/Pasted image 20251008221415.png

Exercise 1 CPU Scheduling: FCFS and SJF

42/44 but might be an encoding error
_attachments/Pasted image 20251008230014.png

Exercise 2 CPU Scheduling: Non-Preemptive Priority & Preemptive Shortest Remaining Time First (SRTF) Scheduling

44/44
_attachments/Pasted image 20251009000208.png
_attachments/Pasted image 20251009000215.png

Exercise 3 Round Robin

17/22
_attachments/Pasted image 20251016121411.png

ANS in parentheses if wrong

P ST CT TAT WT
P1 0 27 27 17
P2 2 17 16 11
P3 6 8 5 3
P4 10 31 26 18
P5 14 29 22 16
AVG 19.2 13
ans key says P2 CT = 27 and P2 TAT = 27 and P2 WT = 17
but if the CT of P2 = 27
and TAT=CT-AT,
P2 CT = 27 ("answer")
P2 AT = 1 (given)
P2 TAT = 27-1 = 26 which isn't in the "answer"

Update: mine was correct
_attachments/Pasted image 20251019222933.png