Practical
CPU Scheduling Algorithms
💡 Harsh Pratap Singh 22BCE10894
First-Come, First-Served (FCFS)
Main concept: Jobs are executed in the order they arrive in the ready queue
Advantages: Simple to implement and understand
Disadvantages: Suffers from convoy effect, where short processes wait behind long ones
Non-preemptive: Once a process starts executing, it continues until completion
code :
Shortest Job First (SJF)
Main concept: Selects the process with the smallest burst time to execute next
Practical 1
Advantages: Optimal average waiting time among non-preemptive algorithms
Disadvantages: Starvation of longer processes, difficult to predict burst times
Non-preemptive: Process runs to completion once started
code :
Shortest Remaining Time First (SRTF)
Main concept: Preemptive version of SJF, always runs the process with shortest remaining
time
Advantages: Optimal average waiting time among all scheduling algorithms
Disadvantages: High context switching overhead, starvation of longer processes
Preemptive: Process can be interrupted when a new process with shorter burst time arrives
code :
Practical 2
Round Robin (RR)
Main concept: Each process gets a small unit of CPU time (time quantum) in a circular
manner
Advantages: Fair allocation, good for time-sharing systems, no starvation
Disadvantages: Performance depends heavily on time quantum selection
Preemptive: Process is preempted after time quantum expires
Time quantum: Critical parameter that affects performance (too small: excessive context
switching, too large: degenerates to FCFS)
code :
Practical 3
Practical 4